Exemplo n.º 1
0
TEST(LeakDetection, BufferOverrunFoundDuringFree)
{
#ifndef USING_OUTPUT_SPY
    TEST_IGNORE();
#else
    void* m = malloc(10);
    char* s = (char*)m;
    TEST_ASSERT_NOT_NULL(m);
    s[10] = (char)0xFF;
    UnityOutputCharSpy_Enable(1);
    EXPECT_ABORT_BEGIN
    free(m);
    EXPECT_ABORT_END
    UnityOutputCharSpy_Enable(0);
    Unity.CurrentTestFailed = 0;
    CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
#endif
}
Exemplo n.º 2
0
void test_mapFind_given_Ali_and_ali_is_in_the_linkedList_in_the_map_should_return_Ali_object3(){
  Person *Ali = personNew("Ali",25,70.3);
  Person *Zorro = personNew("Zorro",60,55.4);
  Person *person;
  
  List *list = listNew(Ali, NULL);
  list = listAdd(Zorro,list);
  
  Map *map = mapNew(5);
  map->bucket[5] = list;
  hash_ExpectAndReturn(Ali,5);
  
  person = mapFind(map , Ali ,comparePerson, hash);
  
  TEST_ASSERT_NOT_NULL(person);
  TEST_ASSERT_EQUAL_Person(Ali,person);
  
}
Exemplo n.º 3
0
void test_stringCreate_will_update_both_based_number_and_identifier()
{
	char *name = "num1";
	char *name1 = "num2";
	DefineElement element;
	element.ID = "num1";
	element.actualID = "200";
	DefineElement element1;
	element1.ID = "num2";
	element1.actualID = "500";
	getElement_ExpectAndReturn(DefineList, name,&element);
	getElement_ExpectAndReturn(DefineList, name1,&element1);
	String * testTokenizer = stringCreate("0x1234-num1+num2%b'101100'");
	TEST_ASSERT_NOT_NULL(testTokenizer);
	TEST_ASSERT_EQUAL_STRING("4660-200+500%44",testTokenizer->rawString);
	TEST_ASSERT_EQUAL(15,testTokenizer->length);
	TEST_ASSERT_EQUAL(0,testTokenizer->startIndex);
	free(testTokenizer);
}
Exemplo n.º 4
0
void test_maplinearStore_given_Ali_but_Ali_is_same_in_Map(){
	CEXCEPTION_T e;
	Person *Ali = personNew("Ali",25,70.3);
	Map *map = mapNew(5);
	
	map->bucket[3] =Ali;
	hash_ExpectAndReturn(Ali,3);
	comparePerson(Ali,Ali);
	
	Try{
		maplinearStore(map , Ali ,comparePerson, hash);
		TEST_FAIL_MESSAGE("Expect ERR_SAME_ELEMENT");
	}
	Catch(e){
	TEST_ASSERT_EQUAL(ERR_SAME_ELEMENT, e);
	TEST_ASSERT_NOT_NULL(map->bucket[3]);
	TEST_ASSERT_EQUAL_Person(Ali,getPersonFromBucketLinear(map->bucket[3]));
	}
}
Exemplo n.º 5
0
void
test_controller_conf_create_and_destroy(void) {
  lagopus_result_t rc;
  controller_conf_t *conf = NULL;
  const char *name = "controller_name";

  controller_initialize();

  // Normal case
  {
    rc = controller_conf_create(&conf, name);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc);
    TEST_ASSERT_NOT_NULL_MESSAGE(conf, "conf_create() will create new controller");

    // name
    TEST_ASSERT_EQUAL_STRING(name, conf->name);

    // current_attr
    TEST_ASSERT_NULL(conf->current_attr);

    // modified_attr
    TEST_ASSERT_NOT_NULL(conf->modified_attr);

    // enabled
    TEST_ASSERT_FALSE(conf->is_enabled);

    // used
    TEST_ASSERT_FALSE(conf->is_used);
  }

  // Abnormal case
  {
    rc = controller_conf_create(NULL, name);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);

    rc = controller_conf_create(&conf, NULL);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);
  }

  controller_conf_destroy(conf);

  controller_finalize();
}
Exemplo n.º 6
0
void
test_controller_get_attr(void) {
  lagopus_result_t rc;
  controller_conf_t *conf = NULL;
  controller_attr_t *attr = NULL;
  const char *name = "controller_name";

  controller_initialize();

  rc = controller_conf_create(&conf, name);
  TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc);
  TEST_ASSERT_NOT_NULL_MESSAGE(conf, "conf_create() will create new controller");

  rc = controller_conf_add(conf);
  TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc);

  // Normal case of getter
  {
    rc = controller_get_attr(name, true, &attr);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_OBJECT, rc);

    rc = controller_get_attr(name, false, &attr);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc);
    TEST_ASSERT_NOT_NULL(attr);
  }

  // Abnormal case of getter
  {
    rc = controller_get_attr(NULL, true, &attr);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);

    rc = controller_get_attr(NULL, false, &attr);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);

    rc = controller_get_attr(name, true, NULL);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);

    rc = controller_get_attr(name, false, NULL);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc);
  }

  controller_finalize();
}
Exemplo n.º 7
0
static void test_pktbuf_start_write__pkt_users_2(void)
{
    gnrc_pktsnip_t *pkt_copy, *pkt = gnrc_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16),
                                                     GNRC_NETTYPE_TEST);

    gnrc_pktbuf_hold(pkt, 1);
    TEST_ASSERT_NOT_NULL((pkt_copy = gnrc_pktbuf_start_write(pkt)));
    TEST_ASSERT(pkt != pkt_copy);
    TEST_ASSERT(pkt->next == pkt_copy->next);
    TEST_ASSERT_EQUAL_STRING(pkt->data, pkt_copy->data);
    TEST_ASSERT_EQUAL_INT(pkt->size, pkt_copy->size);
    TEST_ASSERT_EQUAL_INT(pkt->type, pkt_copy->type);
    TEST_ASSERT_EQUAL_INT(pkt->users, pkt_copy->users);
    TEST_ASSERT_EQUAL_INT(1, pkt->users);

    gnrc_pktbuf_release(pkt_copy);
    gnrc_pktbuf_release(pkt);
    TEST_ASSERT(gnrc_pktbuf_is_empty());
}
Exemplo n.º 8
0
static void test_pktbuf_realloc_data__success(void)
{
    char exp_data[] = TEST_STRING16;
    gnrc_pktsnip_t *pkt;

    pkt = gnrc_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), GNRC_NETTYPE_TEST);

    TEST_ASSERT_NOT_NULL(pkt);

    TEST_ASSERT_EQUAL_INT(0, gnrc_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8)));
    TEST_ASSERT_NULL(pkt->next);
    TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size);
    for (unsigned int i = 0; i < pkt->size; i++) {
        uint8_t *data = pkt->data;
        TEST_ASSERT_EQUAL_INT(exp_data[i], data[i]);
    }
    TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_TEST, pkt->type);
    TEST_ASSERT_EQUAL_INT(1, pkt->users);
}
Exemplo n.º 9
0
void test_metadata ()
{
    char my_endpoint[MAX_SOCKET_STRING];
    setup_test_context ();

    //  Spawn ZAP handler
    //  We create and bind ZAP socket in main thread to avoid case
    //  where child thread does not start up fast enough.
    void *handler = zmq_socket (get_test_context (), ZMQ_REP);
    TEST_ASSERT_NOT_NULL (handler);
    TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (handler, "inproc://zeromq.zap.01"));
    void *zap_thread = zmq_threadstart (&zap_handler, handler);

    void *server = test_context_socket (ZMQ_DEALER);
    void *client = test_context_socket (ZMQ_DEALER);
    TEST_ASSERT_SUCCESS_ERRNO (
      zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "DOMAIN", 6));
    bind_loopback_ipv4 (server, my_endpoint, sizeof (my_endpoint));
    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint));

    s_send (client, "This is a message");
    zmq_msg_t msg;
    zmq_msg_init (&msg);
    TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0));
    TEST_ASSERT_EQUAL_STRING ("World", zmq_msg_gets (&msg, "Hello"));
    TEST_ASSERT_EQUAL_STRING ("DEALER", zmq_msg_gets (&msg, "Socket-Type"));
    TEST_ASSERT_EQUAL_STRING ("anonymous", zmq_msg_gets (&msg, "User-Id"));
    TEST_ASSERT_EQUAL_STRING ("127.0.0.1", zmq_msg_gets (&msg, "Peer-Address"));

    TEST_ASSERT_NULL (zmq_msg_gets (&msg, "No Such"));
    TEST_ASSERT_EQUAL_INT (EINVAL, zmq_errno ());
    zmq_msg_close (&msg);

    test_context_socket_close_zero_linger (client);
    test_context_socket_close_zero_linger (server);

    //  Shutdown
    teardown_test_context ();

    //  Wait until ZAP handler terminates
    zmq_threadclose (zap_thread);
}
Exemplo n.º 10
0
/**
 * \fn test_libcoap_parser_parse_message_with_payload_and_token(void)
 *
 * \brief call coap protocol parser with message with token option and small payload (ACK - changed)
 *
 */
void test_libcoap_parser_parse_message_with_payload_and_token(void)
{
    coap_address.addr_ptr = address;

    sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_token_payload), coap_message_token_payload, NULL);

    TEST_ASSERT_NOT_NULL(coap_header_ptr);

    TEST_ASSERT_EQUAL(COAP_MSG_TYPE_ACKNOWLEDGEMENT, coap_header_ptr->msg_type);
    TEST_ASSERT_EQUAL(COAP_MSG_CODE_RESPONSE_CHANGED, coap_header_ptr->msg_code);
    TEST_ASSERT_EQUAL(0x1234, coap_header_ptr->msg_id);

    TEST_ASSERT_EQUAL(3, coap_header_ptr->token_len);
    TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->token_ptr, sizeof(option_short));

    TEST_ASSERT_EQUAL(3, coap_header_ptr->payload_len);
    TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->payload_ptr, sizeof(option_short));

    sn_coap_parser_release_allocated_coap_msg_mem(handle, coap_header_ptr);
}
Exemplo n.º 11
0
void test_mapStore_given_Ali_but_Ali_is_same_in_Map(){
	CEXCEPTION_T e;
	Person *person = personNew("Ali",25,70.3);
	List *list = listNew(person, NULL);
	Map *map = mapNew(5);
	
	map->bucket[3] =list;
	hash_ExpectAndReturn(person,3);
	comparePerson(person,person);
	
	Try{
		mapStore(map , person ,comparePerson, hash);
		TEST_FAIL_MESSAGE("Expect ERR_SAME_ELEMENT");
	}
	Catch(e){
	TEST_ASSERT_EQUAL(ERR_SAME_ELEMENT, e);
	TEST_ASSERT_NOT_NULL(map->bucket[3]);
	TEST_ASSERT_EQUAL_Person(person,getPersonFromBucket(map->bucket[3]));
	}
}
Exemplo n.º 12
0
static void test_pktbuf_add__in_place(void)
{
    ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16),
                                      NG_NETTYPE_UNDEF);
    ng_pktsnip_t *header;

    TEST_ASSERT_NOT_NULL((header = ng_pktbuf_add(pkt, pkt->data, 4, NG_NETTYPE_UNDEF)));
    TEST_ASSERT(header == pkt->next);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING16, header->data); /* there is no 0 byte */
    TEST_ASSERT_EQUAL_INT(4, header->size);
    TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, header->type);
    TEST_ASSERT_EQUAL_INT(1, header->users);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING16 + 4, pkt->data);
    TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 4, pkt->size);
    TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type);
    TEST_ASSERT_EQUAL_INT(1, pkt->users);
    ng_pktbuf_release(header);
    ng_pktbuf_release(pkt);
    TEST_ASSERT(ng_pktbuf_is_empty());
}
Exemplo n.º 13
0
TEST(allocate_many_small_chunks_with_carving_up, then_new_block_must_be_allocated)
{   
    MemorySet   set             = (MemorySet)mc_amsc;
	MemoryBlock block           = set->blockList;
    MemoryChunk chunk           = (MemoryChunk)((char*)mem_amsc2 - MEM_CHUNK_SIZE);

	int         freeMemSize     = (int)block->freeEnd - (int)block->freeStart;
	int         expectedMemSize = 512 
		                          - MEM_BLOCK_SIZE
								  - chunk->size
								  - MEM_CHUNK_SIZE; 

	TEST_ASSERT_EQUAL_UINT32(block->memset, set);
	TEST_ASSERT_EQUAL_UINT32(freeMemSize, expectedMemSize);
    
	TEST_ASSERT_NOT_NULL(chunk);
	TEST_ASSERT_EQUAL_UINT32(chunk->size, 256);
    TEST_ASSERT_EQUAL_UINT32(chunk->sizeRequested, 205);
	TEST_ASSERT_EQUAL_UINT32(chunk->memsetorchunk, set);
}
Exemplo n.º 14
0
void test_mapStore_given_Zorro_added_into_Ali_in_the_Map(){
	CEXCEPTION_T e;
	Person *person = personNew("Ali",25,70.3);
	Person *Zorro = personNew("Zorro",60,55.4);
	List *list = listNew(person, NULL);
	Map *map = mapNew(5);
	
	map->bucket[3] = list;
	hash_ExpectAndReturn(Zorro,3);
	
	Try{
		mapStore(map , Zorro ,comparePerson, hash);

		TEST_ASSERT_NOT_NULL(map->bucket[3]);
		TEST_ASSERT_EQUAL_Person(Zorro,getPersonFromBucket(map->bucket[3]));
		TEST_ASSERT_EQUAL_Person(person,getPersonFromBucket(((List *)map->bucket[3])->next));
	}
	Catch(e){
		TEST_FAIL_MESSAGE("Expect Zorro");
	}
}
Exemplo n.º 15
0
void test_getToken_should_detect_modulus_sign()
{
	String *testTokenizer = stringCreate("200%10");
	
	//Since the program already can detect 25.
	Token *testToken;
	free(getToken(testTokenizer));
	testToken = getToken(testTokenizer);
	
	//This testToken should be not NULL
	TEST_ASSERT_NOT_NULL(testToken);
	//With operator type.
	TEST_ASSERT_EQUAL(OPERATOR,*testToken);
	Operator *opeToken = (Operator*)testToken;
	TEST_ASSERT_EQUAL(OPERATOR,opeToken->type);
	TEST_ASSERT_EQUAL(MODULUS,opeToken->id);
	TEST_ASSERT_EQUAL(70,opeToken->precedence);
	free(testTokenizer);
	free(opeToken);
	
}
Exemplo n.º 16
0
static void cjson_utils_functions_shouldnt_crash_with_null_pointers(void)
{
    cJSON *item = cJSON_CreateString("item");
    TEST_ASSERT_NOT_NULL(item);

    TEST_ASSERT_NULL(cJSONUtils_GetPointer(item, NULL));
    TEST_ASSERT_NULL(cJSONUtils_GetPointer(NULL, "pointer"));
    TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(NULL, "pointer"));
    TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(item, NULL));
    TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(item, NULL));
    TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(NULL, item));
    TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(item, NULL));
    TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(NULL, item));
    cJSONUtils_AddPatchToArray(item, "path", "add", NULL);
    cJSONUtils_AddPatchToArray(item, "path", NULL, item);
    cJSONUtils_AddPatchToArray(item, NULL, "add", item);
    cJSONUtils_AddPatchToArray(NULL, "path", "add", item);
    cJSONUtils_ApplyPatches(item, NULL);
    cJSONUtils_ApplyPatches(NULL, item);
    cJSONUtils_ApplyPatchesCaseSensitive(item, NULL);
    cJSONUtils_ApplyPatchesCaseSensitive(NULL, item);
    TEST_ASSERT_NULL(cJSONUtils_MergePatch(item, NULL));
    item = cJSON_CreateString("item");
    TEST_ASSERT_NULL(cJSONUtils_MergePatchCaseSensitive(item, NULL));
    item = cJSON_CreateString("item");
    /* these calls are actually valid */
    /* cJSONUtils_MergePatch(NULL, item); */
    /* cJSONUtils_MergePatchCaseSensitive(NULL, item);*/
    /* cJSONUtils_GenerateMergePatch(item, NULL); */
    /* cJSONUtils_GenerateMergePatch(NULL, item); */
    /* cJSONUtils_GenerateMergePatchCaseSensitive(item, NULL); */
    /* cJSONUtils_GenerateMergePatchCaseSensitive(NULL, item); */

    TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(item, NULL));
    TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(NULL, item));
    cJSONUtils_SortObject(NULL);
    cJSONUtils_SortObjectCaseSensitive(NULL);

    cJSON_Delete(item);
}
Exemplo n.º 17
0
static void setup_test(void)
{
    struct dependency_context *ctx = NULL;
    struct output_writter *output = NULL;

    output = get_console_writter();
    TEST_ASSERT_NOT_NULL(output);

    struct memory_allocator *allocator = NULL;

    allocator = get_default_allocator();
    TEST_ASSERT_NOT_NULL(allocator);

    ctx = create_dependency_ctx(create_dependency(output, OUTPUT),
                                create_dependency(allocator, ALLOCATOR),
                                NULL);
    TEST_ASSERT_NOT_NULL(ctx->array);
    TEST_ASSERT(ctx->count == 2);
    uint32_t i;
    for(i = 0; i < ctx->count; i++)
    {
        TEST_ASSERT_NOT_NULL(ctx->array[i]);
    }

    TEST_ASSERT(ctx->array[0]->name == OUTPUT);
    TEST_ASSERT(ctx->array[1]->name == ALLOCATOR);

    inject_crypto_deps(ctx);

    struct random_generator *random_gen = NULL;
    random_gen = get_default_random_generator();
    TEST_ASSERT_NOT_NULL(random_gen);

    int32_t rtrn = 0;

    rtrn = add_dep(ctx, create_dependency(random_gen, RANDOM_GEN));
    TEST_ASSERT(rtrn == 0);

    struct hasher *hasher = NULL;
    hasher = get_hasher();
    TEST_ASSERT_NOT_NULL(hasher);

    rtrn = add_dep(ctx, create_dependency(hasher, HASHER));
    TEST_ASSERT(rtrn == 0);

    inject_utils_deps(ctx);
}
Exemplo n.º 18
0
void test_mapRemove_given_Ali_and_ali_is_not_in_the_linkedList_in_the_map_should_return_NULL4(){
  Person *Ali = personNew("Ali",25,70.3);
  Person *Zorro = personNew("Zorro",60,55.4);
  Person *Kikuri = personNew("Kikuri",50,40.4);
  Person *person;

  List *list = listNew(Kikuri, NULL);
  list = listAdd(Zorro,list);
  
  Map *map = mapNew(5);
  map->bucket[3] = list;
  hash_ExpectAndReturn(Ali,3);
  
  // listDump(list, personDump);
  
  person = mapRemove(map , Ali ,comparePerson, hash);
  
  // listDump(list, personDump);
  
  TEST_ASSERT_NULL(person);
  TEST_ASSERT_NOT_NULL(getPersonFromBucket(map->bucket[3]));
}
Exemplo n.º 19
0
void test_stringCreate_will_update_identifier_to_the_defined_term_if_there_are_two_identifier()
{
	//make it middle.
	char *name = "num1";
	char *name1 = "num2";
	DefineElement element;
	element.ID = "num1";
	element.actualID = "200";
	DefineElement element1;
	element1.ID = "num2";
	element1.actualID = "500";
	getElement_ExpectAndReturn(DefineList, name,&element);
	getElement_ExpectAndReturn(DefineList, name1,&element1);
	getElement_ExpectAndReturn(DefineList, name,&element);
	getElement_ExpectAndReturn(DefineList, name,&element);
	String * testTokenizer = stringCreate("num1+num2-num1+num1");
	
	//Make sure the identifier been updated.
	TEST_ASSERT_NOT_NULL(testTokenizer);
	TEST_ASSERT_EQUAL_STRING("200+500-200+200",testTokenizer->rawString);
	free(testTokenizer);
}
Exemplo n.º 20
0
/**
 *  Case 3
 *
 *  Add Ali into a map. Ali is first hashed and hash value 3 is obtained.
 *  Ali is then placed into bucket 3.
 *  But there is already a person called "Ali".
 */
void test_mapStore_given_Ali_should_throw_exception_when_there_is_already_an_Ali_stored(){
  CEXCEPTION_T e;
  Person *person = personNew("Ali", 25, 70.3);
  List *list = listNew(person, NULL);
  Map *map = mapNew(5);
  
  // hash_ExpectAndReturn(person,3);
  // mapStore(map, person, comparePerson, hash);
  map->bucket[3] = list;
  
  hash_ExpectAndReturn(person,3);
	comparePerson_ExpectAndReturn(person, person, 1);
	
	Try{
		mapStore(map, person, comparePerson, hash);
		TEST_FAIL_MESSAGE("Expect throw exception but did not.");
	}
	Catch(e){
    TEST_ASSERT_EQUAL(ERR_SAME_ELEMENT, e);
    TEST_ASSERT_NOT_NULL(map->bucket[3]);
    TEST_ASSERT_EQUAL_Person(person, getPersonFromBucket(map->bucket[3]));
	}
}
Exemplo n.º 21
0
/**
 *  Case 4
 *
 *  Add Zorro into a map. Zorro is first hashed and hash value 3 is obtained.
 *  Ali is already placed in the bucket 3.
 *  Zorro will then be added to the head of the bucket 3.
 */
void test_mapStore_given_Zorro_should_add_into_the_head_when_there_is_already_an_Ali_stored(){
  CEXCEPTION_T e;
  Person *person1 = personNew("Ali", 25, 70.3);
  Person *person2 = personNew("Zorro", 60, 70.3);
  List *list = listNew(person1, NULL);
  Map *map = mapNew(5);
  
  // hash_ExpectAndReturn(person,3);
  // mapStore(map, person, comparePerson, hash);
  map->bucket[3] = list;
  
  hash_ExpectAndReturn(person2,3);
	comparePerson_ExpectAndReturn(person1, person2, 0);
  
	Try{
		mapStore(map, person2, comparePerson, hash);
    TEST_ASSERT_NOT_NULL(map->bucket[3]);
    TEST_ASSERT_EQUAL_Person(person2, getPersonFromBucket(map->bucket[3]));
    TEST_ASSERT_EQUAL_Person(person1, getPersonFromBucket(( (List *) map->bucket[3] )->next) );
	}
	Catch(e){
    TEST_FAIL_MESSAGE("Expect not to throw exception but thrown.");
	}
}
Exemplo n.º 22
0
void test_mapRemove_given_Ali_and_ali_is_in_the_linkedList_in_the_map_should_return_Ali_object3(){
  Person *Ali = personNew("Ali",25,70.3);
  Person *Zorro = personNew("Zorro",60,55.4);
  Person *person;
  
  List *list = listNew(Ali, NULL);
  list = listAdd(Zorro,list);
  
  Map *map = mapNew(5);
  map->bucket[3] = list;
  hash_ExpectAndReturn(Zorro,3);
  
  // listDump(list, personDump);
  
  person = mapRemove(map , Zorro ,comparePerson, hash);
  
  // listDump(list, personDump);
  
  TEST_ASSERT_NULL(person);
  TEST_ASSERT_NULL(getPersonFromBucket(map->bucket[3]));
  TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next));
  TEST_ASSERT_EQUAL_Person(Ali,getPersonFromBucket(((List *)map->bucket[3])->next));
  
}
Exemplo n.º 23
0
void
test_MultipleElementQueue(void) {
    queue* q = create_queue();

    TEST_ASSERT_NOT_NULL(q);

    element *e1_ptr, *e2_ptr, *e3_ptr;

    e1_ptr = (element*)debug_get_node(sizeof(element));
    e2_ptr = (element*)debug_get_node(sizeof(element));
    e3_ptr = (element*)debug_get_node(sizeof(element));

    enqueue(q, e1_ptr);
    enqueue(q, e2_ptr);
    enqueue(q, e3_ptr);

    TEST_ASSERT_EQUAL(3, get_no_of_elements(q));

    dequeue(q);
    enqueue(q, e1_ptr);

    TEST_ASSERT_EQUAL(3, get_no_of_elements(q));

    dequeue(q);
    dequeue(q);
    enqueue(q, e3_ptr);
    enqueue(q, e2_ptr);

    TEST_ASSERT_EQUAL_PTR(dequeue(q), e1_ptr);
    TEST_ASSERT_EQUAL_PTR(dequeue(q), e3_ptr);
    TEST_ASSERT_EQUAL_PTR(dequeue(q), e2_ptr);
    TEST_ASSERT_EQUAL(0, get_no_of_elements(q));
    TEST_ASSERT_NULL(dequeue(q));

    destroy_queue(q);
}
Exemplo n.º 24
0
void test_KineticBuilder_BuildLockUnlock_should_build_an_UNLOCK_operation_with_PIN_auth(void)
{
    char pinData[] = "abc123";
    ByteArray pin = ByteArray_Create(pinData, strlen(pinData));

    KineticOperation_ValidateOperation_Expect(&Operation);

    KineticBuilder_BuildLockUnlock(&Operation, false, &pin);

    TEST_ASSERT_NOT_NULL(Operation.pin);
    TEST_ASSERT_EQUAL_PTR(&pinData, Operation.pin->data);
    TEST_ASSERT_EQUAL_PTR(strlen(pinData), Operation.pin->len);
    TEST_ASSERT_TRUE(Request.message.command.header->has_messagetype);
    TEST_ASSERT_EQUAL(COM__SEAGATE__KINETIC__PROTO__COMMAND__MESSAGE_TYPE__PINOP,
        Request.message.command.header->messagetype);
    TEST_ASSERT_EQUAL_PTR(&Request.message.body, Request.command->body);
    TEST_ASSERT_EQUAL_PTR(&Request.message.pinOp, Request.command->body->pinop);
    TEST_ASSERT_TRUE(&Request.message.pinOp.has_pinoptype);
    TEST_ASSERT_EQUAL(COM__SEAGATE__KINETIC__PROTO__COMMAND__PIN_OPERATION__PIN_OP_TYPE__UNLOCK_PINOP,
        Request.command->body->pinop->pinoptype);
    TEST_ASSERT_EQUAL_PTR(&KineticCallbacks_Basic, Operation.opCallback);
    TEST_ASSERT_NULL(Operation.response);
    TEST_ASSERT_EQUAL(KineticOperation_TimeoutLockUnlock, Operation.timeoutSeconds);
}
Exemplo n.º 25
0
void test_spiffs_can_opendir(const char* path)
{
    char name_dir_file[64];
    const char * file_name = "test_opd.txt";
    snprintf(name_dir_file, sizeof(name_dir_file), "%s/%s", path, file_name);
    unlink(name_dir_file);
    test_spiffs_create_file_with_text(name_dir_file, "test_opendir\n");
    DIR* dir = opendir(path);
    TEST_ASSERT_NOT_NULL(dir);
    bool found = false;
    while (true) {
        struct dirent* de = readdir(dir);
        if (!de) {
            break;
        }
        if (strcasecmp(de->d_name, file_name) == 0) {
            found = true;
            break;
        }
    }
    TEST_ASSERT_TRUE(found);
    TEST_ASSERT_EQUAL(0, closedir(dir));
    unlink(name_dir_file);
}
void test_convertBasedNumberToBase10Number_will_convert_decimal_number_starting_with_d()
{
	String testTokenizer;
	String *testTokenizer1;
	testTokenizer.rawString = "d'100'";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 6;
	testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	TEST_ASSERT_NOT_NULL(testTokenizer1);
	TEST_ASSERT_EQUAL_STRING("100",testTokenizer1->rawString);
	TEST_ASSERT_EQUAL(0,testTokenizer1->startIndex);
	TEST_ASSERT_EQUAL(3,testTokenizer1->length);
	free(testTokenizer1);

	testTokenizer.rawString = "d'1814561'";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 10;
	testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	TEST_ASSERT_EQUAL_STRING("1814561",testTokenizer1->rawString);
	TEST_ASSERT_EQUAL(0,testTokenizer1->startIndex);
	TEST_ASSERT_EQUAL(7,testTokenizer1->length);
	free(testTokenizer1);
	//*****Error checking tested in test_throwError.c
}
Exemplo n.º 27
0
void test_spiffs_lseek(const char* filename)
{
    FILE* f = fopen(filename, "wb+");
    TEST_ASSERT_NOT_NULL(f);
    TEST_ASSERT_EQUAL(11, fprintf(f, "0123456789\n"));
    TEST_ASSERT_EQUAL(0, fseek(f, -2, SEEK_CUR));
    TEST_ASSERT_EQUAL('9', fgetc(f));
    TEST_ASSERT_EQUAL(0, fseek(f, 3, SEEK_SET));
    TEST_ASSERT_EQUAL('3', fgetc(f));
    TEST_ASSERT_EQUAL(0, fseek(f, -3, SEEK_END));
    TEST_ASSERT_EQUAL('8', fgetc(f));
    TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END));
    TEST_ASSERT_EQUAL(11, ftell(f));
    TEST_ASSERT_EQUAL(4, fprintf(f, "abc\n"));
    TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END));
    TEST_ASSERT_EQUAL(15, ftell(f));
    TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_SET));
    char buf[20];
    TEST_ASSERT_EQUAL(15, fread(buf, 1, sizeof(buf), f));
    const char ref_buf[] = "0123456789\nabc\n";
    TEST_ASSERT_EQUAL_INT8_ARRAY(ref_buf, buf, sizeof(ref_buf) - 1);

    TEST_ASSERT_EQUAL(0, fclose(f));
}
Exemplo n.º 28
0
void test_data_can_create_complex_tree(void)
{
   TEST_IGNORE();
   int tree_data[] = { 4, 2, 6, 1, 3, 5, 7 };
   node_t *tree = build_tree(tree_data, ARRAY_SIZE(tree_data));

   TEST_ASSERT_NOT_NULL(tree);
   TEST_ASSERT_EQUAL_INT(4, tree->data);
   TEST_ASSERT_NOT_NULL(tree->left);
   TEST_ASSERT_NOT_NULL(tree->right);

   TEST_ASSERT_EQUAL_INT(2, tree->left->data);
   TEST_ASSERT_NOT_NULL(tree->left->left);
   TEST_ASSERT_NOT_NULL(tree->left->right);

   TEST_ASSERT_EQUAL_INT(6, tree->right->data);
   TEST_ASSERT_NOT_NULL(tree->right->left);
   TEST_ASSERT_NOT_NULL(tree->right->right);

   TEST_ASSERT_EQUAL_INT(1, tree->left->left->data);
   TEST_ASSERT_NULL(tree->left->left->left);
   TEST_ASSERT_NULL(tree->left->left->right);

   TEST_ASSERT_EQUAL_INT(3, tree->left->right->data);
   TEST_ASSERT_NULL(tree->left->right->left);
   TEST_ASSERT_NULL(tree->left->right->right);

   TEST_ASSERT_EQUAL_INT(5, tree->right->left->data);
   TEST_ASSERT_NULL(tree->right->left->left);
   TEST_ASSERT_NULL(tree->right->left->right);

   TEST_ASSERT_EQUAL_INT(7, tree->right->right->data);
   TEST_ASSERT_NULL(tree->right->right->left);
   TEST_ASSERT_NULL(tree->right->right->right);

   free_tree(tree);
}
Exemplo n.º 29
0
TEST(get_buffer_from_ring, then_a_buffer_should_be_returned)
{
    TEST_ASSERT_NOT_NULL(b_gbfr);
}
Exemplo n.º 30
0
TEST(sml_value, init) {
	sml_value *v = sml_value_init();
	TEST_ASSERT_NOT_NULL(v);
	sml_value_free( v );
}