static void assert_print_object(const char * const expected, const char * const input) { unsigned char printed_unformatted[1024]; unsigned char printed_formatted[1024]; const unsigned char *error_pointer; cJSON item[1]; printbuffer formatted_buffer; printbuffer unformatted_buffer; /* buffer for formatted printing */ formatted_buffer.buffer = printed_formatted; formatted_buffer.length = sizeof(printed_formatted); formatted_buffer.offset = 0; formatted_buffer.noalloc = true; /* buffer for unformatted printing */ unformatted_buffer.buffer = printed_unformatted; unformatted_buffer.length = sizeof(printed_unformatted); unformatted_buffer.offset = 0; unformatted_buffer.noalloc = true; memset(item, 0, sizeof(item)); TEST_ASSERT_NOT_NULL_MESSAGE(parse_object(item, (const unsigned char*)input, &error_pointer, &global_hooks), "Failed to parse object."); TEST_ASSERT_TRUE_MESSAGE(print_object(item, 0, false, &unformatted_buffer, &global_hooks), "Failed to print unformatted string."); TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct."); TEST_ASSERT_TRUE_MESSAGE(print_object(item, 0, true, &formatted_buffer, &global_hooks), "Failed to print formatted string."); TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted ojbect is not correct."); reset(item); }
void test_pwm_timer_create() { t = newPwmTimer(OCR, TimerResolution8, testPin1); TEST_ASSERT_TRUE_MESSAGE(timerValid(t), "pwm-timer not valid after creation"); Pin p = getTimerOutputPin(t); TEST_ASSERT_EQUAL_MESSAGE(testPin1.pointer, p.pointer, "pwm timer has wrong output pin"); TEST_ASSERT_TRUE_MESSAGE(isPwmTimer(t), "pwm timer marked as non-pwm timer"); TEST_ASSERT_EQUAL_MESSAGE(PinPwmOutput, pinOccupation(p), "timer output pin not occupied correctly"); }
static void cjson_array_foreach_should_loop_over_arrays(void) { cJSON array[1]; cJSON elements[10]; cJSON *element_pointer = NULL; size_t i = 0; memset(array, 0, sizeof(array)); memset(elements, 0, sizeof(elements)); /* create array */ array[0].child = &elements[0]; elements[0].prev = NULL; elements[9].next = NULL; for (i = 0; i < 9; i++) { elements[i].next = &elements[i + 1]; elements[i + 1].prev = &elements[i]; } i = 0; cJSON_ArrayForEach(element_pointer, array) { TEST_ASSERT_TRUE_MESSAGE(element_pointer == &elements[i], "Not iterating over array properly"); i++; }
void setUp() { init_fake_port(); twi_tests_setUp(); twea_flag = 0; BOOL res = twi_init(testPin1, testPin2); TEST_ASSERT_TRUE_MESSAGE(res, "failed to initialize twi master."); }
void test_timer_create() { t = newTimer(OCR, TimerResolution8); TEST_ASSERT_TRUE_MESSAGE(timerValid(t), "Timer not valid after creation"); Pin p = getTimerOutputPin(t); TEST_ASSERT_FALSE_MESSAGE(IsValid(p), "Non-pwm timer has output-pin"); TEST_ASSERT_FALSE_MESSAGE(isPwmTimer(t), "Timer should not be pwm timer"); }
static void assert_int_values(array *a, int *ints, int ints_size) { for (int i = 0; i < ints_size; i++) { int *res = array_value(a, i); if (res != NULL) TEST_ASSERT_EQUAL(*res, ints[i]); else if (ints[i] != 0) /* Value 0 can be mistaken with NULL. */ TEST_ASSERT_TRUE_MESSAGE(0, "Array value returned NULL"); } }
static void assert_print_object(const char * const expected, const char * const input) { unsigned char printed_unformatted[1024]; unsigned char printed_formatted[1024]; cJSON item[1]; printbuffer formatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } }; /* buffer for parsing */ parsebuffer.content = (const unsigned char*)input; parsebuffer.length = strlen(input) + sizeof(""); parsebuffer.hooks = global_hooks; /* buffer for formatted printing */ formatted_buffer.buffer = printed_formatted; formatted_buffer.length = sizeof(printed_formatted); formatted_buffer.offset = 0; formatted_buffer.noalloc = true; formatted_buffer.hooks = global_hooks; /* buffer for unformatted printing */ unformatted_buffer.buffer = printed_unformatted; unformatted_buffer.length = sizeof(printed_unformatted); unformatted_buffer.offset = 0; unformatted_buffer.noalloc = true; unformatted_buffer.hooks = global_hooks; memset(item, 0, sizeof(item)); TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer), "Failed to parse object."); unformatted_buffer.format = false; TEST_ASSERT_TRUE_MESSAGE(print_object(item, &unformatted_buffer), "Failed to print unformatted string."); TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct."); formatted_buffer.format = true; TEST_ASSERT_TRUE_MESSAGE(print_object(item, &formatted_buffer), "Failed to print formatted string."); TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted ojbect is not correct."); reset(item); }
void tearDown() { Pin p = Invalid(Pin); if (IsValid(t)) p = getTimerOutputPin(t); t = destroyTimer(t); TEST_ASSERT_TRUE_MESSAGE(!IsValid(t), "Timer still valid after destroy."); if (IsValid(p)) { TEST_ASSERT_EQUAL_MESSAGE(PinNoOccupation, pinOccupation(p), "Pin still occupied after pwm-timer destroyed."); } destroy_fake_port(); }
void tearDown() { expect_conversion_start = FALSE; if (IsValid(analog1)) { analog1 = destroyAnalogInput(analog1); TEST_ASSERT_FALSE_MESSAGE(analogInputValid(analog1), "AnalogInput still valid after destroy"); TEST_ASSERT_FALSE_MESSAGE(IsValid(analog1), "AnalogInput still valid after destroy"); TEST_ASSERT_TRUE_MESSAGE(analog1destroyed, "AnalogInput descriptor was not destroyed"); } if (IsValid(analog2)) { analog2 = destroyAnalogInput(analog2); TEST_ASSERT_FALSE_MESSAGE(analogInputValid(analog2), "AnalogInput still valid after destroy"); TEST_ASSERT_FALSE_MESSAGE(IsValid(analog2), "AnalogInput still valid after destroy"); TEST_ASSERT_TRUE_MESSAGE(analog2destroyed, "AnalogInput descriptor was not destroyed"); } TEST_ASSERT_EQUAL(expected_finished_conversions, finished_conversions); // Make sure no conversions are started anymore triggerConversions(); triggerConversions(); triggerConversions(); }
static void assert_parse_string(const char *string, const char *expected) { parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; buffer.content = (const unsigned char*)string; buffer.length = strlen(string) + sizeof(""); buffer.hooks = global_hooks; TEST_ASSERT_TRUE_MESSAGE(parse_string(item, &buffer), "Couldn't parse string."); assert_is_string(item); TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, item->valuestring, "The parsed result isn't as expected."); global_hooks.deallocate(item->valuestring); item->valuestring = NULL; }
void analogInput_impl_startConversion(void *descriptor) { TEST_ASSERT_TRUE_MESSAGE(expect_conversion_start, "Conversion should not be started anymore"); TEST_ASSERT_TRUE(analogInputCycleRunning()); if ((int) descriptor == 1) { analog1started++; analogInputConversionFinished(analog1value); // This should actually not be done recursively, rather asynchronously } else if ((int) descriptor == 2) { analog2started++; analogInputConversionFinished(analog2value); // This should actually not be done recursively, rather asynchronously } else { TEST_FAIL_MESSAGE("Illegal descriptor pointer"); } }
static void assert_print_number(const char *expected, double input) { unsigned char printed[1024]; cJSON item[1]; printbuffer buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; buffer.buffer = printed; buffer.length = sizeof(printed); buffer.offset = 0; buffer.noalloc = true; buffer.hooks = global_hooks; memset(item, 0, sizeof(item)); cJSON_SetNumberValue(item, input); TEST_ASSERT_TRUE_MESSAGE(print_number(item, &buffer), "Failed to print number."); TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, buffer.buffer, "Printed number is not as expected."); }
static void create2() { analog2 = newAnalogInput((void*) 2); TEST_ASSERT_TRUE_MESSAGE(analogInputValid(analog2), "AnalogInput not valid after create"); TEST_ASSERT_TRUE_MESSAGE(IsValid(analog2), "AnalogInput not valid after create"); TEST_ASSERT_EQUAL_MESSAGE(0, analogInputValue(analog2), "AnalogInput has value after create"); }