@@ -95,39 +95,31 @@ namespace ArduinoContextTest
95
95
TEST_ASSERT_EQUAL (i1, i2);
96
96
}
97
97
98
- void test_print_getter_overload (void )
98
+ void test_unknown_instance_exception (void )
99
99
{
100
- TEST_IGNORE () ;
100
+ fakeit::Mock<Serial_> fake ;
101
101
102
- fakeit::Mock<Serial_> serialFake;
103
- fakeit::Mock<Stream> streamFake;
104
- fakeit::Mock<Print> printFake;
105
-
106
- PrintFake* serialPrintFake = ArduinoFakeInstance (Print, &serialFake.get ());
107
- PrintFake* streamPrintFake = ArduinoFakeInstance (Print, &streamFake.get ());
108
- PrintFake* printFake1 = ArduinoFakeInstance (Print, &printFake.get ());
109
- PrintFake* printFake2 = ArduinoFakeInstance (Print);
110
-
111
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Serial (), serialPrintFake);
112
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Stream (), streamPrintFake);
113
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Print (), printFake1);
114
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Print (), printFake2);
102
+ try {
103
+ ArduinoFakeInstance (Print, &fake.get ());
104
+ } catch (const std::runtime_error& e) {
105
+ TEST_ASSERT_EQUAL_STRING (" Unknown instance" , e.what ());
106
+ }
115
107
}
116
108
117
- void test_stream_getter_overload (void )
109
+ void test_getter_overload_with_proxy (void )
118
110
{
119
- TEST_IGNORE ();
111
+ Serial_* serial = ArduinoFakeMock (Serial);
112
+ PrintFake* fake = ArduinoFakeInstance (Stream, serial);
120
113
121
- fakeit::Mock<Serial_> serialFake ;
122
- fakeit::Mock<Stream> streamFake;
114
+ TEST_ASSERT_EQUAL ( getArduinoFakeContext ()-> Serial (), fake) ;
115
+ }
123
116
124
- PrintFake* serialStreamFake = ArduinoFakeInstance (Stream, &serialFake.get ());
125
- PrintFake* streamFake1 = ArduinoFakeInstance (Stream, &streamFake.get ());
126
- PrintFake* streamFake2 = ArduinoFakeInstance (Stream, &streamFake.get ());
117
+ void test_getter_overload_with_mapping (void )
118
+ {
119
+ Serial_* serial = &::Serial;
120
+ PrintFake* fake = ArduinoFakeInstance (Stream, serial);
127
121
128
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Stream (), serialStreamFake);
129
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Serial (), streamFake2);
130
- TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Stream (), streamFake1);
122
+ TEST_ASSERT_EQUAL (getArduinoFakeContext ()->Serial (), fake);
131
123
}
132
124
133
125
void run_tests (void )
@@ -138,8 +130,9 @@ namespace ArduinoContextTest
138
130
RUN_TEST (ArduinoContextTest::test_print_mock);
139
131
RUN_TEST (ArduinoContextTest::test_stream_mock);
140
132
RUN_TEST (ArduinoContextTest::test_serial_mock);
141
- RUN_TEST (ArduinoContextTest::test_stream_getter_overload);
142
- RUN_TEST (ArduinoContextTest::test_print_getter_overload);
133
+ RUN_TEST (ArduinoContextTest::test_getter_overload_with_proxy);
134
+ RUN_TEST (ArduinoContextTest::test_getter_overload_with_mapping);
135
+ RUN_TEST (ArduinoContextTest::test_unknown_instance_exception);
143
136
}
144
137
}
145
138
0 commit comments