Exemplo n.º 1
0
ssize_t hncp_io_sendto(hncp o, void *buf, size_t len,
                       const char *ifname,
                       const struct in6_addr *dst)
{
  if (check_send)
    {
      sput_fail_unless(o, "hncp");
      sput_fail_unless(o && o->udp_socket == 1, "hncp_io ready");
      smock_pull_string_is("sendto_ifname", ifname);
      struct in6_addr *e_dst = smock_pull("sendto_dst");
      sput_fail_unless(e_dst && memcmp(e_dst, dst, sizeof(*dst)) == 0, "dst match");
      /* Two optional verification steps.. */
      if (_smock_get_queue("sendto_len", false))
        {
          int r_len = smock_pull_int("sendto_len");
          sput_fail_unless(r_len == (int) len, "len");
        }
      if (_smock_get_queue("sendto_buf", false))
        {
          unsigned char *r = smock_pull("sendto_buf");
          sput_fail_unless(memcmp(r, buf, len), "buf");
        }
      return smock_pull_int("sendto_return");
    }
  else
    {
      want_send++;
      return 1;
    }
}
Exemplo n.º 2
0
static void test_intlist_removeall(void)
{
    intlist_t list = intlist_construct(10);

    /* Initialize list to [0, 2, 4, 6, 8] */
    for (int i = 0; i < 5; i++) {
        list = intlist_append(list, 2 * i);
    }

    list = intlist_removeall(list);

    sput_fail_unless(intlist_size(list) == 0,
                     "list = intlist_construct(10),\n"
                     "Initialized list to [0 2 4 6 8],\n"
                     "list = intlist_removeall(list)\n"
                     "Verifying list size is now 0");

    sput_fail_unless(intlist_capacity(list) == 10,
                     "Verifying list capacity remains 10");

    sput_fail_unless(list.elems != NULL,
                     "Verifying list.elems != NULL");

    intlist_destroy(list);
}
Exemplo n.º 3
0
static void test_increase_capacity(void)
{
    /* Initialize a new list to [4, 7, 3, -2, 9] */
    intlist_t list = intlist_construct(5);
    list = intlist_append(list, 4);
    list = intlist_append(list, 7);
    list = intlist_append(list, 3);
    list = intlist_append(list, -2);
    list = intlist_append(list, 9);

    int *old_array = list.elems;

    /* Increase the list's capacity from 5 to 10. */
    list = increase_capacity(list, 10);

    sput_fail_unless(list.capacity == 10,
                     "list = intlist_construct(10);\n"
                     "Initialized list to [4 7 3 -2 9]\n"
                     "list = increase_capacity(list, 10)\n"
                     "Verifying list capacity increased from 5 to 10");
    sput_fail_unless(list.elems != old_array,
                     "Verifying that a new array was allocated");

    int expected[] = {4, 7, 3, -2, 9};
    sput_fail_unless(compare_arrays(list.elems, expected, 5),
                     "Verifying that list still contains [4 7 3 -2 9]");

    intlist_destroy(list);
}
Exemplo n.º 4
0
void test_histogram__capacity(void)
{
	static const size_t HISTO_CAP = USHRT_MAX;

	struct brubeck_histo h;
	struct brubeck_histo_sample sample;
	size_t j;

	memset(&h, 0x0, sizeof(h));

	for (j = 0; j < HISTO_CAP + 500; ++j)
		brubeck_histo_push(&h, (double)(j + 1), 1.0);

	sput_fail_unless(h.size == HISTO_CAP, "histogram size");
	sput_fail_unless(h.count == (HISTO_CAP + 500), "histogram value count");

	brubeck_histo_sample(&sample, &h);

	sput_fail_unless(sample.min == 1.0, "sample.min");
	sput_fail_unless(sample.max == (double)HISTO_CAP, "sample.max");
	sput_fail_unless(sample.count == (HISTO_CAP + 500), "sample.count");

	for (j = 0; j < HISTO_CAP + 500; ++j)
		brubeck_histo_push(&h, (double)(j + 1), 10.0);

	sput_fail_unless(h.size == HISTO_CAP, "histogram size");
	sput_fail_unless(h.count == ((HISTO_CAP + 500) * 10), "histogram value count");

	brubeck_histo_sample(&sample, &h);

	sput_fail_unless(sample.min == 1.0, "sample.min");
	sput_fail_unless(sample.max == (double)HISTO_CAP, "sample.max");
	sput_fail_unless(sample.count == ((HISTO_CAP + 500) * 10), "sample.count");
}
Exemplo n.º 5
0
    void secure_comparator_test(){
      std::string shared_secret_a("shared_secret");
      std::string shared_secret_b("shared_secret");

      themispp::secure_comparator_t a(STR_2_VEC(shared_secret_a));
      themispp::secure_comparator_t b(STR_2_VEC(shared_secret_b));
      
      std::vector<uint8_t> buf;
      
      buf=a.init();
      buf=b.proceed(buf);
      buf=a.proceed(buf);
      buf=b.proceed(buf);
      buf=a.proceed(buf);
      
      sput_fail_unless(a.get(), "a ready", __LINE__);    
      sput_fail_unless(b.get(), "b ready", __LINE__);

      std::string shared_secret_c("shared_secret_c");
      std::string shared_secret_d("shared_secret_d");

      themispp::secure_comparator_t c(STR_2_VEC(shared_secret_c));
      themispp::secure_comparator_t d(STR_2_VEC(shared_secret_d));

      buf=c.init();
      buf=d.proceed(buf);
      buf=c.proceed(buf);
      buf=d.proceed(buf);
      buf=c.proceed(buf);
      
      sput_fail_unless(!(c.get()), "c ready", __LINE__);    
      sput_fail_unless(!(d.get()), "d ready", __LINE__);
    }
Exemplo n.º 6
0
static void test_intlist_get(void)
{
    intlist_t list = intlist_construct(10);

    /* Initialize list to [0, 2, 4, 6, 8] */
    for (int i = 0; i < 5; i++) {
        list = intlist_append(list, 2 * i);
    }

    sput_fail_unless(intlist_get(list, 0) == 0,
                     "list = intlist_construct(10),\n"
                     "Initialized list to [0 2 4 6 8],\n"
		             "Verifying intlist_get(list, 0) returns 0");

    sput_fail_unless(intlist_get(list, 1) == 2,
                     "Verifying intlist_get(list, 1) returns 2");

    sput_fail_unless(intlist_get(list, 2) == 4,
                     "Verifying intlist_get(list, 2) returns 4");

    sput_fail_unless(intlist_get(list, 3) == 6,
                     "Verifying intlist_get(list, 3) returns 6");

    sput_fail_unless(intlist_get(list, 4) == 8,
                     "Verifying intlist_get(list, 4) returns 8");

    intlist_destroy(list);
}
Exemplo n.º 7
0
    void secure_session_test(){
      std::string mes("the test message");
      callback client_callbacks;
      std::string client_id("client");
      std::string server_id("server");
      
      themispp::secure_session_t client(std::vector<uint8_t>(client_id.c_str(), client_id.c_str()+client_id.length()), std::vector<uint8_t>(client_priv, client_priv+sizeof(client_priv)), &client_callbacks);

      callback server_callbacks;
      themispp::secure_session_t server(std::vector<uint8_t>(server_id.c_str(), server_id.c_str()+server_id.length()), std::vector<uint8_t>(server_priv, server_priv+sizeof(server_priv)), &server_callbacks);

      std::vector<uint8_t> control_msg1=client.init();
      std::vector<uint8_t> control_msg2=server.unwrap(control_msg1);
      std::vector<uint8_t> control_msg3=client.unwrap(control_msg2);
      std::vector<uint8_t> control_msg4=server.unwrap(control_msg3);
      std::vector<uint8_t> control_msg5=client.unwrap(control_msg4);
      sput_fail_unless(server.is_established(), "server ready", __LINE__);
      sput_fail_unless(client.is_established(), "client ready", __LINE__);

      std::vector<uint8_t> msg1=client.wrap(std::vector<uint8_t>(mes.c_str(), mes.c_str()+mes.length()+1));
      std::vector<uint8_t> msg2=server.unwrap(msg1);
      sput_fail_unless(strcmp(mes.c_str(), (const char*)(&msg2[0]))==0, "server get message", __LINE__);

      std::vector<uint8_t> msg3=server.wrap(std::vector<uint8_t>(mes.c_str(), mes.c_str()+mes.length()+1));
      std::vector<uint8_t> msg4=client.unwrap(msg3);
      sput_fail_unless(strcmp(mes.c_str(), (const char*)(&msg4[0]))==0, "client get message", __LINE__);
    }
Exemplo n.º 8
0
void dncp_ext_readable(dncp o)
{
  char buf[1024];
  size_t len = sizeof(buf);
  int r;
  struct sockaddr_in6 *src, *dst;
  dncp_ep ep;
  int flags;

  r = o->ext->cb.recv(o->ext, &ep, &src, &dst, &flags, buf, len);
  smock_pull_int_is("dncp_poll_io_recvfrom", r);
  if (r >= 0)
    {
      void *b = smock_pull("dncp_poll_io_recvfrom_buf");
      char *ifn = smock_pull("dncp_poll_io_recvfrom_ifname");
      struct sockaddr_in6 *esrc = smock_pull("dncp_poll_io_recvfrom_src");
      struct sockaddr_in6 *edst = smock_pull("dncp_poll_io_recvfrom_dst");

      sput_fail_unless(memcmp(b, buf, r)==0, "buf mismatch");
      sput_fail_unless(strcmp(ifn, ep->ifname) == 0, "ifname mismatch");
      sput_fail_unless(memcmp(src, esrc, sizeof(*src))==0, "src mismatch");
      sput_fail_unless(memcmp(&dst->sin6_addr,
                              &edst->sin6_addr, sizeof(dst->sin6_addr))==0,
                       "dst mismatch");
      if (!--pending_packets)
        uloop_end();
    }
}
Exemplo n.º 9
0
static void test_modified_intlist_append(void)
{
    int expected[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20};

    /* Construct a list with capacity 10 and fill it. */

    intlist_t list = intlist_construct(10);
    for (int i = 0; i < 10; i += 1) {
        list = intlist_append(list, i * 2);
    }

    /* Now append an integer to the full list.*/

    list = intlist_append(list, 20);

    sput_fail_unless(compare_arrays(list.elems, expected, 11),
                     "list = intlist_construct(10);\n"
		             "Initialized list to [0 2 4 6 8 10 12 14 16 18]\n"
                     "list = intlist_append(list, 20);\n"
		             "Verifying list is now [0 2 4 6 8 10 12 14 16 18 20]");
    sput_fail_unless(list.size == 11,
                     "Verifying list size is now 11");
    sput_fail_unless(list.capacity == 20,
                     "Verifying list capacity is now 20");

    intlist_destroy(list);
}
Exemplo n.º 10
0
bool hncp_io_set_ifname_enabled(hncp o, const char *ifname, bool enabled)
{
  sput_fail_unless(o, "hncp");
  sput_fail_unless(o && o->udp_socket == 1, "hncp_io ready");
  smock_pull_string_is("set_enable_ifname", ifname);
  smock_pull_bool_is("set_enable_enabled", enabled);
  return smock_pull_bool("set_enable_result");
}
Exemplo n.º 11
0
static void dummy_node_cb(hncp_subscriber s, hncp_node n, bool add)
{
  L_NOTICE("node callback %s %s",
           HNCP_NODE_REPR(n), add ? "add" : "remove");
  sput_fail_unless(s, "subscriber provided");
  sput_fail_unless(s->node_change_callback == dummy_node_cb, "node cb set");
  sput_fail_unless(n, "node set");
  smock_pull_bool_is("node_callback", add);
}
void TestAddMemory()	{

    GameProperties testGame;
    testGame = createGame();
    addMemory(100);
    sput_fail_unless(getAvailableMemory() == 100,"Adding MEmory");
    sput_fail_unless(addMemory(-100) == 0,"Adding Negative Memory");
    free(testGame);
}
void CreateGameTest()	{

    GameProperties testGame;
    testGame = getGame(NULL);
    sput_fail_unless(getAvailableMemory() == 1000,"Initializing Memory");
    //sput_fail_unless(getWave(testGame) == 3,"Initializing WaveNo");
    sput_fail_unless(getTotalWaveNo() == 3,"Total Wave Number set to 3 from level file");
    sput_fail_unless(getHealth(testGame) == 100,"Initializing Health");
}
void testlastAction()	{

    GameProperties newGame = getGame(NULL);
    delayGame(ACTIONCOOLDOWN);
    sput_fail_unless(lastAction(newGame) == 1,"Checking delay more than Cooldown returns true");
    delayGame(ACTIONCOOLDOWN-1);
    sput_fail_unless(lastAction(newGame) == 0,"Checking delay less than Cooldown returns false");

}
void testSetLastAction()	{

    GameProperties newGame = getGame(NULL);
    clock_t currTime = clock()/CLOCKS_PER_SEC;
    delayGame(2);
    sput_fail_unless(setlastAction(newGame) == (currTime + 2),"Setting Last Action to current time");
    delayGame(2);
    sput_fail_unless(setlastAction(newGame) == (currTime + 4),"Setting Last Action to current time");
}
void testStartNextWave()	{

    setCurrWaveNum(getGame(NULL)->currWaveNo+1);
    increaseEnemyNumbersThisWave(10);
    getGame(NULL)->deathCount = 0;
    sput_fail_unless(startNextWave() == 0, "Invalid: 10 enemies have not registered as dead yet");
    getGame(NULL)->deathCount = 10;
    sput_fail_unless(startNextWave() == 1, "Valid: 10 enemies have registered as dead");
}
Exemplo n.º 17
0
static void try_parse(struct brubeck_statsd_msg *msg, const char *msg_text, int expect_parse, double expected)
{
	char buffer[64];
	strcpy(buffer, msg_text);

	sput_fail_unless(brubeck_statsd_msg_parse(msg, buffer) == expect_parse, msg_text);
	if(0 == expect_parse) {
		sput_fail_unless(expected == msg->value.n, "msg.value.n == expected");
	}
}
Exemplo n.º 18
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);
}
void TestUseMemory()	{

    GameProperties testGame;
    testGame = createGame();
    testGame->totalMemory = 100;
    useMemory(testGame,50);
    sput_fail_unless(getAvailableMemory() == 50,"Subtracting Memory");
    sput_fail_unless(useMemory(testGame,100) == 0,"Subtracting too much Memory");
    free(testGame);
}
Exemplo n.º 20
0
static void try_parse_set(struct brubeck_statsd_msg *msg, const char *msg_text, int expect_parse, const char *expected)
{
	char buffer[64];
	strcpy(buffer, msg_text);

	sput_fail_unless(brubeck_statsd_msg_parse(msg, buffer) == expect_parse, msg_text);
	if(0 == expect_parse) {
		sput_fail_unless(0 == strcmp(msg->value.s, expected), "msg.value.s == expected");
	}
}
Exemplo n.º 21
0
void Test_CRC()
{
    const char *buffer = "123456789";
    uint32_t crc = 0;
    crc = crc32((uint32_t)0L, (unsigned char *)buffer, (size_t)9);
    sput_fail_unless(crc == 0xCBF43926, "crc32 check");

    crc = crc32(0L, (unsigned char *)NULL, (size_t)1);
    sput_fail_unless(crc == 0, "crc32 check");
}
Exemplo n.º 22
0
void testlastAction()	{

	GameProperties newGame = createGame();
	delayGame(ACTIONCOOLDOWN);
	sput_fail_unless(lastAction(newGame) == 1,"Checking delay more than Cooldown returns true");
	delayGame(ACTIONCOOLDOWN-1);
	sput_fail_unless(lastAction(newGame) == 0,"Checking delay less than Cooldown returns false");
	free(newGame->clock);
	free(newGame);

}
Exemplo n.º 23
0
static void dummy_local_tlv_cb(hncp_subscriber s,
                               struct tlv_attr *tlv, bool add)
{
  sput_fail_unless(s, "subscriber provided");
  sput_fail_unless(s->local_tlv_change_callback == dummy_local_tlv_cb,
                   "tlv cb set");
  sput_fail_unless(tlv, "tlv set");
  L_NOTICE("local tlv callback %s %s", TLV_REPR(tlv), add ? "add" : "remove");
  if (tlv_id(tlv) == HNCP_T_VERSION) return;
  int exp_v = (add ? 1 : -1) * tlv_id(tlv);
  smock_pull_int_is("local_tlv_callback", exp_v);
}
Exemplo n.º 24
0
static void test_gettm_fail()
{
	Task task;
	task.description = "(A) do hw START: bob";
	sput_fail_unless(gettms(&task) == NULL, "gettm(): start fail test");
 
	task.description = "(A) do hw END: bob";
	sput_fail_unless(gettms(&task) == NULL, "gettm(): end fail test");

	task.description = "(A) do hw START: bob END: larry";
	sput_fail_unless(gettms(&task) == NULL, "gettm(): end fail test");
}
Exemplo n.º 25
0
void test_fls64()
{
    sput_fail_unless(bit_fls(0ull)==-1, "Edge case: arg=0");
    sput_fail_unless(bit_fls(1ull)==0,  "arg=1");
    sput_fail_unless(bit_fls(0xFFFFFFFFFFFFFFFFull)==63,  "arg=0xFFFFFFFF");
    sput_fail_unless(bit_ffs(0x8000000000000000ull)==63,  "arg=0x8000000000000000");

    for (uint64_t i=0; i<64; ++i)
    {
        sput_fail_unless(bit_fls(1ull<<i)==i, "General Test");
        sput_fail_unless(bit_fls(0xFFFFFFFFFFFFFFFFull>>i)==63-i, "General test1");
    }
}
Exemplo n.º 26
0
void test_fls32()
{
    sput_fail_unless(bit_fls(0u)==-1, "Edge case: arg=0");
    sput_fail_unless(bit_fls(1u)==0,  "arg=1");
    sput_fail_unless(bit_fls(0xFFFFFFFFu)==31,  "arg=0xFFFFFFFF");
    sput_fail_unless(bit_fls(0x80000000u)==31,  "arg=0x80000000");

    for (uint32_t i=0; i<32; ++i)
    {
        sput_fail_unless(bit_fls(1u<<i)==i, "General Test0");
        sput_fail_unless(bit_fls(0xFFFFFFFFu>>i)==31-i, "General test1");
    }
}
Exemplo n.º 27
0
void hncp_io_schedule(hncp o, int msecs)
{
  if (check_timing)
    {
      sput_fail_unless(o, "hncp");
      sput_fail_unless(o && o->udp_socket == 1, "hncp_io ready");
      smock_pull_int_is("schedule", msecs);
    }
  else
    {
      want_schedule = msecs;
    }
}
Exemplo n.º 28
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");
}
Exemplo n.º 29
0
static void test_intlist_construct(void)
{
    intlist_t list = intlist_construct(10);
    sput_fail_unless(list.capacity == 10,
                     "list = intlist_construct(10),\n"
                     "Verifying list.capacity == 10");
    sput_fail_unless(list.size == 0,
                     "Verifying list.size == 0");
    sput_fail_unless(list.elems != NULL,
                     "Verifying list.elems is not NULL");

    intlist_destroy(list);
}
Exemplo n.º 30
0
/*
* creates two enemies and checks their defaut values
*/
void Test_createEnemy()
{
    freeAllEnemies();

    createEnemy();
    sput_fail_unless(getNumberOfEnemies() == 1, "Valid: Number of enemies held in group is one.");
    
    sput_fail_unless(getEnemyHealth(getNumberOfEnemies()) == 100,"Valid: Enemy health is default." );

    createEnemy();
    sput_fail_unless(getNumberOfEnemies() == 2, "Valid: Number of enemies held in group is two.");
    sput_fail_unless(getEnemyHealth(getNumberOfEnemies()) == 100,"Valid: Enemy 2  health is default." );

}