44 lines
2.5 KiB
C
44 lines
2.5 KiB
C
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "set_trends.h"
|
|
|
|
int main(void)
|
|
{
|
|
const uint8_t data[] = {1, 0, 254, 255};
|
|
const uint32_t id = 0x1FD31234UL; /* priority 1, from device, type 7, dev 13, GAS */
|
|
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, 1, data, 4) == 65534);
|
|
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 1, id, 1, data, 4) == -2);
|
|
assert(set_trend_can_value(1, 0x1233, 7, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_can_value(1, 0x1236, 7, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_can_value(1, 0x1235, 6, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_can_value(1, 0x1235, 7, 12, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id ^ 0x08000000UL, 1, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, 1, data, 3) == SET_TREND_NO_VALUE);
|
|
for (unsigned flag = 2; flag <= 8; flag <<= 1) {
|
|
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, (uint8_t)(1 | flag), data, 4) == SET_TREND_NO_VALUE);
|
|
}
|
|
assert(set_trend_can_value(2, 0x321, 0, 0, 2, 0, 1, 0x321, 0, data, 4) == -2);
|
|
assert(set_trend_can_value(2, 0x321, 0, 0, 3, 0, 1, 0x321, 0, data, 4) == SET_TREND_NO_VALUE);
|
|
assert(set_trend_word_value(0x8000, 1) == -32768);
|
|
assert(set_trend_word_value(0xFFFF, 0) == 65535);
|
|
const uint16_t addresses[] = {0x1234, 0xFFFF};
|
|
const uint8_t expected[] = {232, 3, 2, 0, 52, 18, 255, 255};
|
|
uint8_t output[132];
|
|
assert(set_trend_watch_request(1000, addresses, 2, output, sizeof(output)) == 8);
|
|
assert(memcmp(expected, output, 8) == 0);
|
|
assert(set_trend_watch_request(1000, addresses, 65, output, sizeof(output)) == 0);
|
|
assert(set_trend_watch_request(1000, NULL, 2, output, sizeof(output)) == 0);
|
|
assert(set_trend_watch_request(1000, addresses, 2, output, 7) == 0);
|
|
assert(set_trend_watch_ack(expected, 4, 1000, 2));
|
|
assert(!set_trend_watch_ack(expected, 4, 1000, 3));
|
|
const uint8_t packet[] = {1, 2, 3, 4, 2, 0, 52, 18, 255, 255};
|
|
uint16_t words[64];
|
|
assert(set_trend_watch_values(packet, sizeof(packet), words, 64) == 2);
|
|
assert(words[0] == 0x1234 && words[1] == 0xFFFF);
|
|
assert(set_trend_watch_values(packet, sizeof(packet) - 1, words, 64) == -1);
|
|
assert(set_trend_watch_values(packet, sizeof(packet), words, 1) == -1);
|
|
puts("Shared trend tests passed");
|
|
return 0;
|
|
}
|