Exercise: Mocking Switch (Non-Polymorphic)

Requirements

Implement a switch class which does not access any real hardware, but rather will be used for testing (“mocking”).

#include <gtest/gtest.h>

#include <switch-mock-nopoly.h>


TEST(switch_mock_suite, initial_state)
{
    {
        MockSwitch_nopoly sw(MockSwitch_nopoly::State::OFF);
        ASSERT_TRUE(sw.state() == MockSwitch_nopoly::State::OFF);
    }
    {
        MockSwitch_nopoly sw(MockSwitch_nopoly::State::ON);
        ASSERT_TRUE(sw.state() == MockSwitch_nopoly::State::ON);
    }
}

TEST(switch_mock_suite, set_on_off)
{
    MockSwitch_nopoly sw(MockSwitch_nopoly::State::OFF);
    ASSERT_TRUE(sw.state() == MockSwitch_nopoly::State::OFF);
    sw.on();
    ASSERT_TRUE(sw.state() == MockSwitch_nopoly::State::ON);
    sw.off();
    ASSERT_TRUE(sw.state() == MockSwitch_nopoly::State::OFF);
}

Topics Covered

cluster_c The C Programming Language cluster_c_introduction Introduction cluster_linux Linux cluster_linux_toolchain Toolchain, And Cross Development cluster_linux_basics Linux Basics cluster_linux_basics_intro Introduction: Concepts and Terminology cluster_linux_basics_shell The Shell (Bash - “Bourne Again Shell”) cluster_cxx03 C++ cluster_cxx03_data_encapsulation Data Encapsulation cluster_cxx C++: Miscellaneous Live-Hacking cluster_cxx_exercises C++ Exercises c_introduction_installation Installation linux_toolchain_static_library Object Code Archives/Static Libraries linux_toolchain_separate_compilation Zooming In: Separate Compilation, and Linking Statically linux_toolchain_static_library->linux_toolchain_separate_compilation linux_toolchain_basics Toolchain: Basics linux_basics_shell_file_dir_create_rm Creating And Removing Files and Directories linux_toolchain_basics->linux_basics_shell_file_dir_create_rm linux_toolchain_cmake_local CMake: Local Build linux_toolchain_cmake_local->linux_toolchain_static_library linux_toolchain_separate_compilation->linux_toolchain_basics linux_basics_intro_process Processes, Scheduling, Address Spaces linux_basics_intro_overview Overview linux_basics_intro_process->linux_basics_intro_overview linux_basics_shell_paths Absolute and Relative Paths linux_basics_shell_file_dir_create_rm->linux_basics_shell_paths linux_basics_shell_cwd Current Working Directory linux_basics_shell_file_dir_create_rm->linux_basics_shell_cwd linux_basics_shell_commandline Commandline linux_basics_shell_paths->linux_basics_shell_commandline linux_basics_shell_cwd->linux_basics_intro_process linux_basics_shell_cwd->linux_basics_shell_paths linux_basics_shell_cwd->linux_basics_shell_commandline linux_basics_shell_commandline->linux_basics_intro_overview cxx03_introduction Introduction cxx03_introduction->c_introduction_installation cxx03_data_encapsulation_classes_objects Classes and Objects cxx03_data_encapsulation_classes_objects->cxx03_introduction cxx03_data_encapsulation_c Object Oriented Programming In Good Ol’ C cxx03_data_encapsulation_classes_objects->cxx03_data_encapsulation_c cxx03_data_encapsulation_c->cxx03_introduction cxx_exercises_switch_mock_nopoly Exercise: Mocking Switch (Non-Polymorphic) cxx_exercises_switch_mock_nopoly->linux_toolchain_cmake_local cxx_exercises_switch_mock_nopoly->cxx03_data_encapsulation_classes_objects