Skip to content

Commit 1f0b9ec

Browse files
committed
Fix tests
1 parent d609a27 commit 1f0b9ec

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_target: all
33
all: clean build test clean
44

55
cmake:
6-
@cmake -DCMAKE_BUILD_TYPE=Debug $(CURDIR) -B$(CURDIR)/build
6+
@cmake $(CURDIR) -B$(CURDIR)/build
77

88
build: cmake
99
@cd $(CURDIR)/build && make all

test/test_context.h

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,31 @@ namespace ArduinoContextTest
9595
TEST_ASSERT_EQUAL(i1, i2);
9696
}
9797

98-
void test_print_getter_overload(void)
98+
void test_unknown_instance_exception(void)
9999
{
100-
TEST_IGNORE();
100+
fakeit::Mock<Serial_> fake;
101101

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+
}
115107
}
116108

117-
void test_stream_getter_overload(void)
109+
void test_getter_overload_with_proxy(void)
118110
{
119-
TEST_IGNORE();
111+
Serial_* serial = ArduinoFakeMock(Serial);
112+
PrintFake* fake = ArduinoFakeInstance(Stream, serial);
120113

121-
fakeit::Mock<Serial_> serialFake;
122-
fakeit::Mock<Stream> streamFake;
114+
TEST_ASSERT_EQUAL(getArduinoFakeContext()->Serial(), fake);
115+
}
123116

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);
127121

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);
131123
}
132124

133125
void run_tests(void)
@@ -138,8 +130,9 @@ namespace ArduinoContextTest
138130
RUN_TEST(ArduinoContextTest::test_print_mock);
139131
RUN_TEST(ArduinoContextTest::test_stream_mock);
140132
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);
143136
}
144137
}
145138

0 commit comments

Comments
 (0)