migrating to googletest

This commit is contained in:
rusefi 2019-01-14 15:48:47 -05:00
parent 4b95e5f124
commit 4c9de98100
1 changed files with 64 additions and 64 deletions

View File

@ -28,7 +28,7 @@
#include "gtest/gtest.h"
TEST(util, crc) {
assertEquals(4, efiRound(4.4, 1));
ASSERT_EQ(4, efiRound(4.4, 1));
assertEquals(1.2, efiRound(1.2345, 0.1));
print("*************************************** testCrc\r\n");
@ -55,13 +55,13 @@ TEST(util, Overflow64Counter) {
print("*************************************** testOverflow64Counter\r\n");
Overflow64Counter o;
assertEquals(0, o.update(0));
assertEquals(10, o.update(10));
ASSERT_EQ(0, o.update(0));
ASSERT_EQ(10, o.update(10));
assertEquals(20, o.update(20));
ASSERT_EQ(20, o.update(20));
// overflow
assertEquals(4294967296, o.update(0));
ASSERT_EQ(4294967296, o.update(0));
}
TEST(util, cyclicBufferContains) {
@ -79,10 +79,10 @@ TEST(util, cyclicBuffer) {
{
sb.add(10);
assertEquals(10, sb.sum(3));
ASSERT_EQ(10, sb.sum(3));
sb.add(2);
assertEquals(12, sb.sum(2));
ASSERT_EQ(12, sb.sum(2));
}
{
sb.clear();
@ -92,10 +92,10 @@ TEST(util, cyclicBuffer) {
sb.add(3);
sb.add(4);
assertEquals(4, sb.maxValue(3));
assertEquals(4, sb.maxValue(113));
ASSERT_EQ(4, sb.maxValue(3));
ASSERT_EQ(4, sb.maxValue(113));
assertEqualsM("minValue(3)", 2, sb.minValue(3));
assertEquals(1, sb.minValue(113));
ASSERT_EQ(1, sb.minValue(113));
}
}
@ -105,26 +105,26 @@ TEST(util, histogram) {
initHistogramsModule();
assertEquals(80, histogramGetIndex(239));
assertEquals(223, histogramGetIndex(239239));
assertEquals(364, histogramGetIndex(239239239));
ASSERT_EQ(80, histogramGetIndex(239));
ASSERT_EQ(223, histogramGetIndex(239239));
ASSERT_EQ(364, histogramGetIndex(239239239));
histogram_s h;
initHistogram(&h, "test");
int result[5];
assertEquals(0, hsReport(&h, result));
ASSERT_EQ(0, hsReport(&h, result));
hsAdd(&h, 10);
assertEquals(1, hsReport(&h, result));
assertEquals(10, result[0]);
ASSERT_EQ(1, hsReport(&h, result));
ASSERT_EQ(10, result[0]);
// let's add same value one more time
hsAdd(&h, 10);
assertEquals(2, hsReport(&h, result));
assertEquals(10, result[0]);
assertEquals(10, result[1]);
ASSERT_EQ(2, hsReport(&h, result));
ASSERT_EQ(10, result[0]);
ASSERT_EQ(10, result[1]);
hsAdd(&h, 10);
hsAdd(&h, 10);
@ -133,14 +133,14 @@ TEST(util, histogram) {
hsAdd(&h, 1000);
hsAdd(&h, 100);
assertEquals(5, hsReport(&h, result));
ASSERT_EQ(5, hsReport(&h, result));
assertEquals(5, result[0]);
assertEquals(10, result[1]);
assertEquals(10, result[2]);
assertEquals(100, result[3]);
ASSERT_EQ(5, result[0]);
ASSERT_EQ(10, result[1]);
ASSERT_EQ(10, result[2]);
ASSERT_EQ(100, result[3]);
// values are not expected to be exactly the same, it's the shape what matters
assertEquals(1011, result[4]);
ASSERT_EQ(1011, result[4]);
}
static void testMalfunctionCentralRemoveNonExistent() {
@ -159,7 +159,7 @@ static void testMalfunctionCentralSameElementAgain() {
addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
getErrorCodes(&localCopy);
assertEquals(1, localCopy.count);
ASSERT_EQ(1, localCopy.count);
}
static void testMalfunctionCentralRemoveFirstElement() {
@ -173,14 +173,14 @@ static void testMalfunctionCentralRemoveFirstElement() {
obd_code_e secondElement = OBD_Intake_Air_Temperature_Circuit_Malfunction;
addError(secondElement);
getErrorCodes(&localCopy);
assertEquals(2, localCopy.count);
ASSERT_EQ(2, localCopy.count);
// let's remove first element - code
removeError(firstElement);
getErrorCodes(&localCopy);
assertEquals(1, localCopy.count);
assertEquals(secondElement, localCopy.error_codes[0]);
ASSERT_EQ(1, localCopy.count);
ASSERT_EQ(secondElement, localCopy.error_codes[0]);
}
TEST(misc, testMalfunctionCentral) {
@ -195,7 +195,7 @@ TEST(misc, testMalfunctionCentral) {
// on start-up error storage should be empty
getErrorCodes(&localCopy);
assertEquals(0, localCopy.count);
ASSERT_EQ(0, localCopy.count);
obd_code_e code = OBD_Engine_Coolant_Temperature_Circuit_Malfunction;
// let's add one error and validate
@ -203,29 +203,29 @@ TEST(misc, testMalfunctionCentral) {
getErrorCodes(&localCopy);
assertEqualsM("count #1", 1, localCopy.count);
assertEquals(code, localCopy.error_codes[0]);
ASSERT_EQ(code, localCopy.error_codes[0]);
// let's remove value which is not in the collection
removeError((obd_code_e) 22);
// element not present - nothing to removed
assertEquals(1, localCopy.count);
assertEquals(code, localCopy.error_codes[0]);
ASSERT_EQ(1, localCopy.count);
ASSERT_EQ(code, localCopy.error_codes[0]);
code = OBD_Intake_Air_Temperature_Circuit_Malfunction;
addError(code);
getErrorCodes(&localCopy);
// todo: assertEquals(2, localCopy.count);
// todo: ASSERT_EQ(2, localCopy.count);
for (int code = 0; code < 100; code++) {
addError((obd_code_e) code);
}
getErrorCodes(&localCopy);
assertEquals(MAX_ERROR_CODES_COUNT, localCopy.count);
ASSERT_EQ(MAX_ERROR_CODES_COUNT, localCopy.count);
// now we have full array and code below present
removeError(code);
getErrorCodes(&localCopy);
assertEquals(MAX_ERROR_CODES_COUNT - 1, localCopy.count);
ASSERT_EQ(MAX_ERROR_CODES_COUNT - 1, localCopy.count);
}
static int lastInteger = -1;
@ -315,13 +315,13 @@ TEST(misc, testConsoleLogic) {
helpCommand();
char * cmd = "he ha";
assertEquals(2, findEndOfToken(cmd));
ASSERT_EQ(2, findEndOfToken(cmd));
cmd = "\"hee\" ha";
assertEquals(5, findEndOfToken(cmd));
ASSERT_EQ(5, findEndOfToken(cmd));
cmd = "\"h e\" ha";
assertEquals(5, findEndOfToken(cmd));
ASSERT_EQ(5, findEndOfToken(cmd));
strcpy(buffer, "echo");
ASSERT_TRUE(strEqual("echo", unquote(buffer)));
@ -330,8 +330,8 @@ TEST(misc, testConsoleLogic) {
assertTrueM("unquote quoted", strEqual("echo", unquote(buffer)));
char *ptr = validateSecureLine(UNKNOWN_COMMAND);
assertEquals(0, strcmp(UNKNOWN_COMMAND, ptr));
assertEquals(10, tokenLength(UNKNOWN_COMMAND));
ASSERT_EQ(0, strcmp(UNKNOWN_COMMAND, ptr));
ASSERT_EQ(10, tokenLength(UNKNOWN_COMMAND));
// handling invalid token should work
strcpy(buffer, "sdasdafasd asd");
@ -341,33 +341,33 @@ TEST(misc, testConsoleLogic) {
addConsoleActionI("echoi", testEchoI);
strcpy(buffer, "echoi 239");
handleConsoleLine(buffer);
assertEquals(239, lastInteger);
ASSERT_EQ(239, lastInteger);
print("\r\naddConsoleActionI 240 with two spaces\r\n");
strcpy(buffer, "echoi 240");
handleConsoleLine(buffer);
assertEquals(240, lastInteger);
ASSERT_EQ(240, lastInteger);
print("\r\naddConsoleActionII\r\n");
addConsoleActionII("echoii", testEchoII);
strcpy(buffer, "echoii 22 239");
handleConsoleLine(buffer);
assertEquals(22, lastInteger);
assertEquals(239, lastInteger2);
ASSERT_EQ(22, lastInteger);
ASSERT_EQ(239, lastInteger2);
print("\r\naddConsoleActionII three spaces\r\n");
strcpy(buffer, "echoii 21 220");
handleConsoleLine(buffer);
assertEquals(21, lastInteger);
assertEquals(220, lastInteger2);
ASSERT_EQ(21, lastInteger);
ASSERT_EQ(220, lastInteger2);
print("\r\addConsoleActionSSS\r\n");
addConsoleActionSSS("echosss", testEchoSSS);
strcpy(buffer, "echosss 111 222 333");
handleConsoleLine(buffer);
assertEquals(111, atoi(lastFirst));
assertEquals(333, atoi(lastThird));
ASSERT_EQ(111, atoi(lastFirst));
ASSERT_EQ(333, atoi(lastThird));
strcpy(buffer, "echosss \" 1\" 222 333");
handleConsoleLine(buffer);
@ -380,30 +380,30 @@ TEST(misc, testFLStack) {
print("******************************************* testFLStack\r\n");
FLStack<int, 4> stack;
assertEquals(0, stack.size());
ASSERT_EQ(0, stack.size());
stack.push(123);
stack.push(234);
assertEquals(2, stack.size());
ASSERT_EQ(2, stack.size());
int v = stack.pop();
assertEquals(234, v);
assertEquals(1, stack.size());
assertEquals(123, stack.get(0));
ASSERT_EQ(234, v);
ASSERT_EQ(1, stack.size());
ASSERT_EQ(123, stack.get(0));
v = stack.pop();
assertEquals(123, v);
assertEquals(0, stack.size());
ASSERT_EQ(123, v);
ASSERT_EQ(0, stack.size());
stack.push(123);
stack.push(234);
stack.push(345);
stack.push(456);
assertEquals(4, stack.size());
ASSERT_EQ(4, stack.size());
stack.remove(123);
assertEquals(456, stack.get(0));
assertEquals(3, stack.size());
ASSERT_EQ(456, stack.get(0));
ASSERT_EQ(3, stack.size());
}
static char buff[32];
@ -428,8 +428,8 @@ TEST(misc, testMisc) {
assertTrueM("NaN atoff", cisnan(v));
}
// assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
// assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
// ASSERT_EQ(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
// ASSERT_EQ(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
}
TEST(misc, testMenuTree) {
@ -451,9 +451,9 @@ TEST(misc, testMenuTree) {
MenuItem miSubMenu5_1(&miTopLevel5, "sub menu 5 1");
MenuItem miSubMenu5_2(&miTopLevel5, "sub menu 5 2");
assertEquals(0, miTopLevel1.index);
assertEquals(1, miTopLevel2.index);
assertEquals(4, miTopLevel5.index);
ASSERT_EQ(0, miTopLevel1.index);
ASSERT_EQ(1, miTopLevel2.index);
ASSERT_EQ(4, miTopLevel5.index);
tree.init(&miTopLevel1, 3);