migrating to googletest

This commit is contained in:
rusefi 2019-01-14 15:37:05 -05:00
parent 73aa22573e
commit cc300145b3
5 changed files with 28 additions and 36 deletions

View File

@ -11,7 +11,7 @@
#include "unit_test_framework.h" #include "unit_test_framework.h"
static void testIndex(const int expected, const float array[], int size, float value) { static void testIndex(const int expected, const float array[], int size, float value) {
assertEquals(expected, findIndex(array, size, value)); ASSERT_EQ(expected, findIndex(array, size, value));
assertEquals(expected, findIndex2(array, size, value)); assertEquals(expected, findIndex2(array, size, value));
} }

View File

@ -45,30 +45,30 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
static void testParsing(void) { static void testParsing(void) {
char buffer[64]; char buffer[64];
assertTrue(strEqualCaseInsensitive("hello", "HELlo")); ASSERT_TRUE(strEqualCaseInsensitive("hello", "HELlo"));
assertFalse(strEqualCaseInsensitive("hello", "HElo2")); ASSERT_FALSE(strEqualCaseInsensitive("hello", "HElo2"));
const char *ptr; const char *ptr;
ptr = getNextToken(" hello ", buffer, sizeof(buffer)); ptr = getNextToken(" hello ", buffer, sizeof(buffer));
assertTrue(strEqual("hello", buffer)); ASSERT_TRUE(strEqual("hello", buffer));
ptr = getNextToken("hello", buffer, sizeof(buffer)); ptr = getNextToken("hello", buffer, sizeof(buffer));
assertTrue(strEqual("hello", buffer)); ASSERT_TRUE(strEqual("hello", buffer));
ptr = getNextToken(" hello world ", buffer, sizeof(buffer)); ptr = getNextToken(" hello world ", buffer, sizeof(buffer));
assertTrue(strEqual("hello", buffer)); ASSERT_TRUE(strEqual("hello", buffer));
ptr = getNextToken(ptr, buffer, sizeof(buffer)); ptr = getNextToken(ptr, buffer, sizeof(buffer));
assertTrue(strEqual("world", buffer)); ASSERT_TRUE(strEqual("world", buffer));
assertTrue(isNumeric("123")); ASSERT_TRUE(isNumeric("123"));
assertFalse(isNumeric("a123")); ASSERT_FALSE(isNumeric("a123"));
LEElement thepool[TEST_POOL_SIZE]; LEElement thepool[TEST_POOL_SIZE];
LEElementPool pool(thepool, TEST_POOL_SIZE); LEElementPool pool(thepool, TEST_POOL_SIZE);
LEElement *element; LEElement *element;
element = pool.parseExpression("1 3 AND not"); element = pool.parseExpression("1 3 AND not");
assertTrue(element != NULL); ASSERT_TRUE(element != NULL);
assertEquals(element->action, LE_NUMERIC_VALUE); assertEquals(element->action, LE_NUMERIC_VALUE);
assertEquals(element->fValue, 1.0); assertEquals(element->fValue, 1.0);
@ -84,7 +84,7 @@ static void testParsing(void) {
assertEquals(element->action, LE_OPERATOR_NOT); assertEquals(element->action, LE_OPERATOR_NOT);
element = element->next; element = element->next;
assertTrue(element == NULL); ASSERT_TRUE(element == NULL);
} }
static void testExpression2(float selfValue, const char *line, float expected) { static void testExpression2(float selfValue, const char *line, float expected) {

View File

@ -83,13 +83,13 @@ static void testDodgeNeonDecoder(void) {
// assertFalseM("4 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization // assertFalseM("4 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
// //
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
// assertFalse(state.shaft_is_synchronized); // still no synchronization // ASSERT_FALSE(state.shaft_is_synchronized); // still no synchronization
// //
// printf("2nd camshaft revolution\r\n"); // printf("2nd camshaft revolution\r\n");
// r = 720; // r = 720;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
// assertTrue(state.shaft_is_synchronized); // ASSERT_TRUE(state.shaft_is_synchronized);
// assertEquals(0, state.current_index); // assertEquals(0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
// assertEquals(1, state.current_index); // assertEquals(1, state.current_index);
@ -101,7 +101,7 @@ static void testDodgeNeonDecoder(void) {
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
// assertEqualsM("current index", 3, state.current_index); // assertEqualsM("current index", 3, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
// assertTrue(state.shaft_is_synchronized); // ASSERT_TRUE(state.shaft_is_synchronized);
// assertEqualsM("current index", 0, state.current_index); // assertEqualsM("current index", 0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
@ -127,7 +127,7 @@ TEST(misc, testSomethingWeird) {
sta->decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r PASS_ENGINE_PARAMETER_SUFFIX); sta->decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r PASS_ENGINE_PARAMETER_SUFFIX);
assertFalseM("shaft_is_synchronized", sta->shaft_is_synchronized); // still no synchronization assertFalseM("shaft_is_synchronized", sta->shaft_is_synchronized); // still no synchronization
sta->decodeTriggerEvent(SHAFT_PRIMARY_RISING, ++r PASS_ENGINE_PARAMETER_SUFFIX); sta->decodeTriggerEvent(SHAFT_PRIMARY_RISING, ++r PASS_ENGINE_PARAMETER_SUFFIX);
assertTrue(sta->shaft_is_synchronized); // first signal rise synchronize ASSERT_TRUE(sta->shaft_is_synchronized); // first signal rise synchronize
assertEquals(0, sta->getCurrentIndex()); assertEquals(0, sta->getCurrentIndex());
sta->decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r++ PASS_ENGINE_PARAMETER_SUFFIX); sta->decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
assertEquals(1, sta->getCurrentIndex()); assertEquals(1, sta->getCurrentIndex());

View File

@ -324,7 +324,7 @@ TEST(misc, testConsoleLogic) {
assertEquals(5, findEndOfToken(cmd)); assertEquals(5, findEndOfToken(cmd));
strcpy(buffer, "echo"); strcpy(buffer, "echo");
assertTrue(strEqual("echo", unquote(buffer))); ASSERT_TRUE(strEqual("echo", unquote(buffer)));
strcpy(buffer, "\"echo\""); strcpy(buffer, "\"echo\"");
assertTrueM("unquote quoted", strEqual("echo", unquote(buffer))); assertTrueM("unquote quoted", strEqual("echo", unquote(buffer)));
@ -371,7 +371,7 @@ TEST(misc, testConsoleLogic) {
strcpy(buffer, "echosss \" 1\" 222 333"); strcpy(buffer, "echosss \" 1\" 222 333");
handleConsoleLine(buffer); handleConsoleLine(buffer);
assertTrue(strEqual("\" 1\"", lastFirst)); ASSERT_TRUE(strEqual("\" 1\"", lastFirst));
//addConsoleActionSSS("GPS", testGpsParser); //addConsoleActionSSS("GPS", testGpsParser);
} }
@ -412,7 +412,7 @@ TEST(misc, testMisc) {
print("******************************************* testMisc\r\n"); print("******************************************* testMisc\r\n");
strcpy(buff, " ab "); strcpy(buff, " ab ");
// we need a mutable array here // we need a mutable array here
assertTrue(strEqual("ab", efiTrim(buff))); ASSERT_TRUE(strEqual("ab", efiTrim(buff)));
{ {
@ -458,25 +458,25 @@ TEST(misc, testMenuTree) {
tree.init(&miTopLevel1, 3); tree.init(&miTopLevel1, 3);
tree.nextItem(); tree.nextItem();
assertTrue(tree.topVisible == &miTopLevel1); ASSERT_TRUE(tree.topVisible == &miTopLevel1);
assertTrue(tree.current == &miTopLevel2); ASSERT_TRUE(tree.current == &miTopLevel2);
tree.back(); tree.back();
assertTrue(tree.current == &miTopLevel2); // no 'back' since we are on the top level already ASSERT_TRUE(tree.current == &miTopLevel2); // no 'back' since we are on the top level already
tree.nextItem(); tree.nextItem();
assertTrue(tree.topVisible == &miTopLevel1); ASSERT_TRUE(tree.topVisible == &miTopLevel1);
assertTrue(tree.current == &miTopLevel3); ASSERT_TRUE(tree.current == &miTopLevel3);
tree.nextItem(); tree.nextItem();
assertTrue(tree.topVisible == &miTopLevel2); ASSERT_TRUE(tree.topVisible == &miTopLevel2);
assertTrue(tree.current == &miTopLevel4); ASSERT_TRUE(tree.current == &miTopLevel4);
tree.enterSubMenu(); tree.enterSubMenu();
assertTrueM("still same", tree.current == &miTopLevel4); // no children in this one assertTrueM("still same", tree.current == &miTopLevel4); // no children in this one
tree.nextItem(); tree.nextItem();
assertTrue(tree.topVisible == &miTopLevel3); ASSERT_TRUE(tree.topVisible == &miTopLevel3);
assertTrueM("tl5", tree.current == &miTopLevel5); assertTrueM("tl5", tree.current == &miTopLevel5);
tree.nextItem(); tree.nextItem();
@ -489,10 +489,10 @@ TEST(misc, testMenuTree) {
tree.nextItem(); tree.nextItem();
tree.enterSubMenu(); tree.enterSubMenu();
assertTrue(tree.current == &miSubMenu5_1); ASSERT_TRUE(tree.current == &miSubMenu5_1);
tree.back(); tree.back();
assertTrue(tree.current == &miTopLevel1); ASSERT_TRUE(tree.current == &miTopLevel1);
} }
int getRusEfiVersion(void) { int getRusEfiVersion(void) {

View File

@ -53,18 +53,10 @@ void assertTrueM(const char *msg, float actual) {
assertEqualsM(msg, TRUE, actual); assertEqualsM(msg, TRUE, actual);
} }
void assertTrue(float actual) {
assertTrueM("", actual);
}
void assertFalseM(const char *msg, float actual) { void assertFalseM(const char *msg, float actual) {
assertEqualsM(msg, FALSE, actual); assertEqualsM(msg, FALSE, actual);
} }
void assertFalse(float actual) {
assertFalseM("", actual);
}
void chDbgAssert(int c, char *msg, void *arg) { void chDbgAssert(int c, char *msg, void *arg) {
if (!c) { if (!c) {
printf("assert failed: %s\r\n", msg); printf("assert failed: %s\r\n", msg);