5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <QApplication>
28 using ::testing::TestEventListener
;
29 using ::testing::EmptyTestEventListener
;
30 using ::testing::Test
;
31 using ::testing::TestCase
;
32 using ::testing::TestEventListeners
;
33 using ::testing::TestInfo
;
34 using ::testing::TestPartResult
;
35 using ::testing::UnitTest
;
36 using ::testing::InitGoogleTest
;
40 void printColorCode(int color
)
43 if (isatty(fileno(stdout
)))
44 fprintf(stdout
, "\033[0;%dm", color
);
49 * Replaces gtest's PrettyUnitTestResultPrinter with something less verbose.
50 * Uses the default printer if/when the messages might be interesting,
51 * e.g. for full error info or tests summary.
53 class TersePrinter
: public EmptyTestEventListener
{
55 explicit TersePrinter(TestEventListener
* prettyPrinter
)
56 : prettyPrinter(prettyPrinter
), currentTestInfo(NULL
)
59 void OnTestProgramStart(const UnitTest
& unit_test
)
61 prettyPrinter
->OnTestProgramStart(unit_test
);
63 void OnTestIterationStart(const UnitTest
& unit_test
, int iteration
)
66 fprintf(stdout
, "############ ");
67 fprintf(stdout
, "Running %d test(s) from %d test case(s), iteration: %d.\n", unit_test
.test_to_run_count(), unit_test
.test_case_to_run_count(), iteration
+ 1);
71 void OnTestCaseStart(const TestCase
& test_case
)
73 prettyPrinter
->OnTestCaseStart(test_case
);
75 void OnTestStart(const TestInfo
& test_info
)
77 currentTestInfo
= &test_info
;
79 void OnTestPartResult(const TestPartResult
& test_part_result
)
81 if (test_part_result
.failed()) {
82 prettyPrinter
->OnTestStart(*currentTestInfo
);
83 prettyPrinter
->OnTestPartResult(test_part_result
);
86 void OnTestEnd(const TestInfo
& test_info
)
88 currentTestInfo
= NULL
;
89 if (test_info
.result()->Failed()) {
90 prettyPrinter
->OnTestEnd(test_info
);
99 void OnTestCaseEnd(const TestCase
& test_case
)
101 fprintf(stdout
, "\n");
104 void OnTestIterationEnd(const UnitTest
& unit_test
, int iteration
)
106 prettyPrinter
->OnTestIterationEnd(unit_test
, iteration
);
108 void OnTestProgramEnd(const UnitTest
& unit_test
)
110 prettyPrinter
->OnTestProgramEnd(unit_test
);
114 // gtest's default unit test result printer.
115 std::unique_ptr
<TestEventListener
> prettyPrinter
;
116 // The currently running TestInfo, if any.
117 const TestInfo
* currentTestInfo
;
120 } // anonymous namespace
123 uint16_t anaInValues
[NUM_STICKS
+NUM_POTS
+NUM_SLIDERS
] = { 0 };
124 uint16_t anaIn(uint8_t chan
)
126 if (chan
< NUM_STICKS
+NUM_POTS
+NUM_SLIDERS
)
127 return anaInValues
[chan
];
132 uint16_t getAnalogValue(uint8_t index
)
137 static char _stringResult
[200];
138 const char * zchar2string(const char * zstring
, int size
)
140 if (size
> (int)sizeof(_stringResult
) ) {
143 zchar2str(_stringResult
, zstring
, size
);
144 return _stringResult
;
147 const char * nchar2string(const char * string
, int size
)
149 if (size
> (int)sizeof(_stringResult
) ) {
152 strncpy(_stringResult
, string
, size
);
153 _stringResult
[size
] = '\0';
154 return _stringResult
;
158 int main(int argc
, char **argv
)
160 QCoreApplication
app(argc
, argv
);
162 StartEepromThread(nullptr);
163 #if defined(EEPROM_SIZE)
164 eeprom
= (uint8_t *)malloc(EEPROM_SIZE
);
167 menuHandlers
[0] = menuMainView
;
168 InitGoogleTest(&argc
, argv
);
170 // use --verbose option to revert to gtest's default output format
171 bool verbose
= false;
172 if (argc
> 1 && !strcmp(argv
[1], "--verbose"))
176 TestEventListeners
& listeners
= UnitTest::GetInstance()->listeners();
177 TestEventListener
* defaultPrinter
= listeners
.Release(listeners
.default_result_printer());
178 listeners
.Append(new TersePrinter(defaultPrinter
));
181 return RUN_ALL_TESTS();