Esempio n. 1
0
void bmemcpy_shift_t(void)
{
	uint8_t u1[] = {0xff, 0xff, 0xff, 0xff};
	uint8_t u2[] = {0x00, 0x00, 0x00, 0x00};
	uint8_t u3[] = {0x03, 0xff, 0xfc, 0x00};
	uint8_t u4[] = {0x00, 0x18, 0x00, 0x00};
	uint8_t u5[] = {0x00, 0x00, 0xff, 0xe0};
	uint8_t u6[] = {0x01, 0x80, 0x00, 0x00};

	bmemcpy_shift(u2, 6, u1, 6, 16);
	sput_fail_if(memcmp(u2, u3, 4), "Copy 16 bits without shift");
	memset(u2, 0, 4);

	bmemcpy_shift(u2, 6, u1, 5, 16);
	sput_fail_if(memcmp(u2, u3, 4), "Copy 16 bits with shift");
	memset(u2, 0, 4);

	bmemcpy_shift(u2, 11, u1, 7, 2);
	sput_fail_if(memcmp(u2, u4, 4), "Copy 2 bits");
	memset(u2, 0, 4);

	bmemcpy_shift(u2, 16, u1, 5, 11);
	sput_fail_if(memcmp(u2, u5, 4), "Copy 11 bits");
	memset(u2, 0, 4);

	bmemcpy_shift(u2, 7, u1, 11, 2);
	sput_fail_if(memcmp(u2, u6, 4), "Copy 2 bits");
	memset(u2, 0, 4);
}
Esempio n. 2
0
void bmemcpy_t(void)
{
	uint8_t u1[] = {0xff, 0xff, 0xff, 0xff};
	uint8_t u2[] = {0x00, 0x00, 0x00, 0x00};
	uint8_t u3[] = {0xff, 0xff, 0x00, 0x00};
	uint8_t u4[] = {0x07, 0xff, 0xff, 0x00};
	uint8_t u5[] = {0x01, 0xff, 0xff, 0xc0};
	uint8_t u6[] = {0x00, 0xff, 0xff, 0xf0};
	uint8_t dst[4];

	bmemcpy(&dst, &u2, 0, 32);
	sput_fail_if(memcmp(dst, u2, 4), "32bit copy");

	memset(dst, 0, 4);
	bmemcpy(&dst, &u1, 0, 16);
	sput_fail_if(memcmp(dst, u3, 4), "16bit copy");

	memset(dst, 0, 4);
	bmemcpy(&dst, &u1, 5, 19);
	sput_fail_if(memcmp(dst, u4, 4), "5 to 24 bits copy");

	memset(dst, 0, 4);
	bmemcpy(&dst, &u1, 7, 19);
	sput_fail_if(memcmp(dst, u5, 4), "7 to 26 bits copy");

	memset(dst, 0, 4);
	bmemcpy(&dst, &u1, 8, 20);
	sput_fail_if(memcmp(dst, u6, 4), "8 to 28 bits copy");

}
Esempio n. 3
0
void prefix_increment_t(void)
{
	struct prefix px;

	sput_fail_unless(prefix_increment(&px, &p1, 8) == 0, "Ret is 0");
	sput_fail_if(prefix_cmp(&px, &p2), "px == p2");

	sput_fail_unless(prefix_increment(&px, &p10, 8) == 0, "Ret is 0");
	sput_fail_if(prefix_cmp(&px, &p11), "px == p11");

	sput_fail_unless(prefix_increment(&px, &p10, 16) == 1, "Single possibility");
	sput_fail_if(prefix_cmp(&px, &p10), "px == p10");

	sput_fail_unless(prefix_increment(&px, &p1f, 12) == 1, "Looping");
	sput_fail_if(prefix_cmp(&px, &p10), "px == p10");

	sput_fail_unless(prefix_increment(&px, &p1f, 120) == -1, "Forbidden");

	px.plen = 120;
	sput_fail_unless(prefix_increment(&px, &px, 4) == -1, "Forbidden");
	px.plen = 42;
	sput_fail_unless(prefix_increment(&px, &px, 10) == 0, "32 bits authorized");
	px.plen = 43;
	sput_fail_unless(prefix_increment(&px, &px, 10) == -1, "33 bits forbidden");
}
Esempio n. 4
0
static void testUnknownMode(void)
{
    int err;
    DaStruct da;
    da.magic = DA_MAGIC;

    sput_fail_if(daClear(&da, &err, 123456) != -1, "daClear should fail if we pass an unknown mode");
    sput_fail_if(err != (DA_PARAM_ERR | DA_UNKNOWN_MODE), "err != (DA_PARAM_ERR | DA_UNKNOWN_MODE)");
}
Esempio n. 5
0
static void testMagic(void)
{
    int err;
    DaStruct da;

    da.magic = DA_MAGIC + 1;

    sput_fail_if(daClear(&da, &err, 0) != -1, "daClear should fail if the magic number mismatches");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");
}
Esempio n. 6
0
static void testNull(void)
{
    int err;
    DaStruct da;
    memset(&da, '1', sizeof(da));

    sput_fail_if(daClear(NULL, NULL, 0) != -1, "daClear(NULL, NULL, 0) != -1");
    sput_fail_if(daClear(&da,  NULL, 0) != -1, "daClear(&da,  NULL, 0) != -1");
    sput_fail_if(daClear(NULL, &err, 0) != -1, "daClear(NULL, &err, 0) != -1");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");
}
Esempio n. 7
0
void prefix_print_nocan_t(void)
{
	char buff[PREFIX_MAXBUFFLEN];
	const char *ret;

	ret = prefix_ntop(buff, 5, &p_allones_128, false);
	sput_fail_if(ret, "Buffer too short (1)");

	ret = prefix_ntop(buff, 43,
			&p_allones_128, false);
	sput_fail_if(ret, "Buffer too short (2)");
}
Esempio n. 8
0
void prefix_contains_t(void)
{
	sput_fail_if(prefix_contains(&p1, &p2),
			"p1 and p2 are disjoint");
	sput_fail_if(prefix_contains(&p2, &p1),
			"p1 and p2 are disjoint");
	sput_fail_unless(prefix_contains(&p1, &p11),
			"p1 contains p11");
	sput_fail_unless(prefix_contains(&p1, &p1f),
			"p1 contains p1f");
	sput_fail_if(prefix_contains(&p2, &p11),
			"p2 do not contain p11");
}
Esempio n. 9
0
static void testValid(void)
{
    int err;
    const char *src;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 10;
    desc.bytesPerElement = 1;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");


    sput_fail_if(daClear(da, &err, DA_FAST) != 0, "daClear should succeed if we clear fast");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(da->used != 0, "daClear should reset the used counter");



    src = "5555555555";
    memcpy(da->firstAddr, src, 10);
    da->used = 10;

    sput_fail_if(daClear(da, &err, DA_SECURE) != 0, "daClear should succeed if we clear fast");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(da->used != 0, "daClear should reset the used counter");
    src = "0000000000";
    sput_fail_if(memcmp(da->firstAddr, src, 10) != 0, "daClear in secure mode doesn't erase the array content");

    daDestroy(da, &err);
}
Esempio n. 10
0
void prefix_last_t(void)
{
	struct prefix px;
	sput_fail_unless(prefix_last(&px, &p10, 18) == -1, "Forbidden arg");

	sput_fail_unless(prefix_last(&px, &p10, 16) == 0, "Ret is 0");
	sput_fail_if(prefix_cmp(&px, &p10), "Unmodified");

	sput_fail_unless(prefix_last(&px, &p10, 12) == 0, "Ret is 0");
	sput_fail_if(prefix_cmp(&px, &p1f), "px == p1f");

	sput_fail_unless(prefix_last(&px, &p11, 12) == 0, "Ret is 0");
	sput_fail_if(prefix_cmp(&px, &p1f), "px == p1f");
}
Esempio n. 11
0
void prefix_number_t()
{
	struct prefix p;
	prefix_number(&p, &p10, 0, 1);
	sput_fail_if(prefix_cmp(&p, &p10), "Correct prefix");
	prefix_number(&p, &p10, 1, 1);
	sput_fail_if(prefix_cmp(&p, &p11), "Correct prefix");
	prefix_number(&p, &p10, 1, 0);
	sput_fail_if(prefix_cmp(&p, &p10), "Correct prefix");
	prefix_number(&p, &p10, 0xf, 1);
	sput_fail_if(prefix_cmp(&p, &p11), "Correct prefix");
	prefix_number(&p, &p10, 0xf, 4);
	sput_fail_if(prefix_cmp(&p, &p1f), "Correct prefix");
}
Esempio n. 12
0
void prefix_equal_t(void)
{
	sput_fail_if(prefix_cmp(&p_allones_67, &p_allones_67),
			"Same prefixes should be equal (1)");
	sput_fail_if(prefix_cmp(&p_allones_67_can, &p_allones_67_can),
			"Same prefixes should be equal (2)");
	sput_fail_if(prefix_cmp(&p1, &p1),
			"Same prefixes should be equal (3)");
	sput_fail_if(prefix_cmp(&p_allones_67, &p_allones_67_can),
			"Canonical prefix should equal non-canonical one");
	sput_fail_unless(prefix_cmp(&p1, &p10),
			"Different prefix length should imply not equal");
	sput_fail_unless(prefix_cmp(&p1, &p_allones_67),
			"Different prefixes should not be equal");
}
Esempio n. 13
0
static void test_getrecur()
{
	Task task;
	task.description = "(A) do hw RECUR: Fri";
	sput_fail_if(getrecurtm(" Fri",&task) == NULL, "RECUR succeed test");

	task.description = "(A) do hw RECUR: ";
	sput_fail_unless(gettms(&task) == NULL, "RECUR fail test");

	task.description = "(A) do hw RECUR: Fri START: 08/22/14 08:00 END: 08-22-14 09:22";
	sput_fail_if(gettms(&task) == NULL, "RECUR succeed test with start/end");

	task.description = "(A) do hw RECUR: START: 08/22/14 08:00 END: 08-22-14 09:22";
	sput_fail_unless(gettms(&task) == NULL, "RECUR fail test with start/end");
}
Esempio n. 14
0
void sample(void)
{
  int r;

  L_DEBUG("debug");
  L_INFO("info");
  L_NOTICE("notice");
  L_WARN("warn");
  L_ERR("err");

  sput_fail_if(0, "0 isn't false!");
  sput_fail_unless(1, "1 isn't true!");

  /* Play with smock */
  sput_fail_unless(smock_empty(), "smock empty");
  smock_push_int("in", 1);
  sput_fail_unless(!smock_empty(), "smock not empty");
  smock_push_int("out", 2);
  smock_push_int("in", 3);
  smock_push_int("out", 6);
  r = dummy_callback(1);
  sput_fail_unless(r == 2, "dummy_callback broken");
  r = dummy_callback(3);
  sput_fail_unless(r == 6, "dummy_callback broken");
  /* In the end, we should be again gone. */
  sput_fail_unless(smock_empty(), "smock empty");
}
Esempio n. 15
0
void prefix_canonical_t(void)
{
	struct prefix p;
	prefix_canonical(&p, &p_allones_67);

	sput_fail_if(memcmp(&p, &p_allones_67_can, sizeof(struct prefix)),
				"Canonical transform");
}
Esempio n. 16
0
void mjson_invalid_syntax_tests()
{
    mjson_element_t top_element;

    for (int i = 0; i < ARRAY_SIZE(invalid_json); ++i)
    {
        sput_fail_if(mjson_parse(invalid_json[i], strlen(invalid_json[i]), bjson, sizeof(bjson), &top_element), "");
    }
}
Esempio n. 17
0
void CreateGameTest()	{

	GameProperties testGame;
	testGame = createGame();
	sput_fail_if((createGame()) == NULL,"Creating Game");
	sput_fail_unless(getAvailableMemory(testGame) == 0,"Initializing Memory");
	sput_fail_unless(getWave(testGame) == 0,"Initializing WaveNo");
	sput_fail_unless(getHealth(testGame) == 0,"Initializing Health");
	free(testGame);
}
Esempio n. 18
0
void prefix_print_can_t(void)
{
	char buff[PREFIX_MAXBUFFLEN];
	const char *ret;

	ret = prefix_ntop(buff, PREFIX_MAXBUFFLEN, &p_allones_67, true);
	sput_fail_if(strcmp(ret, p_allones_67_can_s), "Canonical prefix print");

	ret = prefix_ntop(buff, PREFIX_MAXBUFFLEN, &p_allones_67, false);
	sput_fail_if(strcmp(ret, p_allones_67_s), "Non canonical prefix print");


	ret = prefix_ntop(buff, PREFIX_MAXBUFFLEN,
				&p_allones_128, false);
	sput_fail_if(strcmp(ret, p_allones_128_s), "Print all_ones/128");

	ret = prefix_ntop(buff, PREFIX_MAXBUFFLEN,
			&p1, false);
	sput_fail_if(strcmp(ret, p1_s), "Print p1");

	ret = prefix_ntop(buff, PREFIX_MAXBUFFLEN,
			&px, false);
	sput_fail_if(strcmp(ret, px_s), "Print px");
}
Esempio n. 19
0
void prefix_random_t(void)
{
	int i;
	struct prefix p;

	sput_fail_unless(prefix_random(&p_allones_67, &p, 60),
			"Too short plen for random prefix");

	prefix_random(&p_allones_67_can, &p, 67);
	sput_fail_if(prefix_cmp(&p_allones_67_can, &p),
			"Only one possible random prefix");

	bool success = true;
	for(i = 0; i < 20; i++) {
		prefix_random(&p_allones_67, &p, 70);
		if(!prefix_contains(&p_allones_67, &p)) {
			success = false;
			break;
		}
	}
	sput_fail_unless(success, "Random prefix is in src prefix");
}
Esempio n. 20
0
static void testValid(void)
{
    int err;
    DaStruct da;

    da.magic = DA_MAGIC;
    da.used = 0;
    sput_fail_if(daIsEmpty(&da, &err) != 1, "daIsEmpty(...) should return 1 if array is empty");
    sput_fail_if(err != DA_OK, "err != DA_OK");

    da.used = 1;
    sput_fail_if(daIsEmpty(&da, &err) != 0, "daIsEmpty(...) should return 0 if array isn't empty");
    sput_fail_if(err != DA_OK, "err != DA_OK");

    da.used = 2;
    sput_fail_if(daIsEmpty(&da, &err) != 0, "daIsEmpty(...) should return 0 if array isn't empty");
    sput_fail_if(err != DA_OK, "err != DA_OK");
}
Esempio n. 21
0
static void test_gettm_success()
{
	Task task;
	task.description = "(A) do hw START: 08/22/14 08:00 END: 08-22-14 09:22";
	sput_fail_if(gettms(&task) == NULL, "gettm(): start/end succeed test");
}