Ejemplo n.º 1
0
TEST(utilities, IPv6Address) {
	const struct in6_addr address = {{{
						0x20, 0x01, 0x0d, 0xb8,
						0x85, 0xa3, 0x08, 0xd3,
						0x13, 0x19, 0x8a, 0x2e,
						0x03, 0x70, 0x73, 0x34
					}}};
	const char *expected = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
	sockaddr_u	input;
	struct addrinfo	inputA;

	memset(&input, 0, sizeof(input));
	input.sa6.sin6_family = AF_INET6;
	input.sa6.sin6_addr = address;
	/* coverity[leaked_storage] */
	TEST_ASSERT_EQUAL_STRING(expected, ss_to_str(&input));

	inputA = CreateAddrinfo(&input);
	/* coverity[leaked_storage] */
TEST_ASSERT_EQUAL_STRING(expected, addrinfo_to_str(&inputA));
}
Ejemplo n.º 2
0
static void test_ipv6_addr_to_str__success2(void)
{
    ng_ipv6_addr_t a = { {
            0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
        }
    };
    char result[NG_IPV6_ADDR_MAX_STR_LEN];

    TEST_ASSERT_EQUAL_STRING("fe80::f8f9:fafb:fcfd:feff",
                             ng_ipv6_addr_to_str(result, &a, sizeof(result)));
}
/************************************************************************************************************
 * The JsonList for the findElement Function to test are as shown below,                                    *
 *                                                                                                          *
 *  {                                                                                                       *
 *    "NAME1":"JS",                                                                                         *
 *    "NAME2":20,                                                                                           *
 *    "NAME3":"STEVEN",                                                                                     *
 *  }                                                                                                       *
 *                                                                                                          *
 * -Test to find the 'Key'="AGE".                                                                           *
 *                                                                                                          *
 ************************************************************************************************************/
void test_Finding_Element_if_Key_not_Found_in_the_Simple_JSON_List_Should_Throw_Error()
{
  printf("JSON list Finding Element test No.1\n");
  JsonObject *jsonObj;
  Token *jsonTok;
  ListElement *findKey;
  Token *findVal;
  ErrorObject *err;

  TOKEN_DECLARE;

  getToken_ExpectAndReturn(openBrace0);    //"{"
  getToken_ExpectAndReturn(NAME1);         //"NAME1"
  getToken_ExpectAndReturn(colon0);        //":"
  getToken_ExpectAndReturn(JS);            //"JS"
  getToken_ExpectAndReturn(coma0);         //","
  getToken_ExpectAndReturn(NAME2);         //"NAME2"
  getToken_ExpectAndReturn(colon1);        //":"
  getToken_ExpectAndReturn(int20);         //20
  getToken_ExpectAndReturn(coma1);         //","
  getToken_ExpectAndReturn(NAME3);         //"NAME3"
  getToken_ExpectAndReturn(colon2);        //":"
  getToken_ExpectAndReturn(STEVEN);        //"STEVEN"
  getToken_ExpectAndReturn(closeBrace0);   //"}"
  getToken_ExpectAndReturn(dollarSign);

  jsonObj=createJsonObject();

  Try{
    jsonTok=jsonParse(jsonObj);
  }Catch(err){
    TEST_FAIL_JSON("unexpected error occurred =>'%s'",err->errorMsg);
    free(err);
  }

  TEST_ASSERT_EQUAL(END,jsonObj->state);
  Try{
    findKey=keyFind(((JsonToken *)jsonTok)->list, "AGE", strCompare);
    TEST_FAIL_MESSAGE("Expecting ERR_KEY_NOT_FOUND to be thrown, but none thrown.");
  }Catch(err){
    TEST_ASSERT_EQUAL_STRING("ERROR[14]:Key not Found.Finding 'Key'=>'AGE'.",err->errorMsg);
    TEST_ASSERT_EQUAL(ERR_KEY_NOT_FOUND,err->errorCode);
    free(err);
  }

  free(jsonObj);
  free(jsonTok);
  free(findKey);
  free(findVal);

  TOKEN_FREE;
  printf("\n\n");
}
Ejemplo n.º 4
0
void test_requestbuilder_BuildsWithHeaders(void)
{
    builder.putHeader("Host", "www.example.com");
    builder.putHeader("Content-Type", "text/html");
    builder.putHeader("Some-Other-Header", "Some-Other-Value");
    builder.writeToBuffer(requestBuffer, 512);
    TEST_ASSERT_EQUAL_STRING(
        "GET / HTTP/1.1\r\n"
        "Host: www.example.com\r\n"
        "Content-Type: text/html\r\n"
        "Some-Other-Header: Some-Other-Value\r\n", requestBuffer);
}
Ejemplo n.º 5
0
static void test_ipv6_addr_to_str__success(void)
{
    ng_ipv6_addr_t a = { {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
        }
    };
    char result[NG_IPV6_ADDR_MAX_STR_LEN];

    TEST_ASSERT_EQUAL_STRING("1:203:405:607:809:a0b:c0d:e0f",
                             ng_ipv6_addr_to_str(result, &a, sizeof(result)));
}
Ejemplo n.º 6
0
void test_GetEmptyCookieF()
{
  char* cookiestra = "NYT_W2=IndianapolisINUS";
  const char* cookiename = "NYT_W2";
  const char* expected="IndianapolisINUS";

  char* actual = get_weather_code_from_cookie(cookiestra, cookiename);
  printf("I have:%s:\n", actual);

  TEST_ASSERT_EQUAL_STRING(expected, actual);

}
Ejemplo n.º 7
0
static void test_pktbuf_merge_data__success2(void)
{
    gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, TEST_STRING4,
                                          sizeof(TEST_STRING4),
                                          GNRC_NETTYPE_TEST);

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

    TEST_ASSERT_EQUAL_INT(0, gnrc_pktbuf_merge(pkt));
    TEST_ASSERT_NULL(pkt->next);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING16, pkt->data);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING8,
                             (char *) pkt->data + sizeof(TEST_STRING16));
    TEST_ASSERT_EQUAL_STRING(TEST_STRING4,
                             (char *) pkt->data + sizeof(TEST_STRING16) +
                             sizeof(TEST_STRING8));
    gnrc_pktbuf_release(pkt);
    TEST_ASSERT(gnrc_pktbuf_is_empty());
    TEST_ASSERT(gnrc_pktbuf_is_sane());
}
Ejemplo n.º 8
0
void test_labels(void) {
    init_hash_table();
    Instruction* i = new_instruction_label("test", 1);
    TEST_ASSERT_EQUAL_STRING("test", i->opcode);
    TEST_ASSERT(i->type = I_TYPE_LABEL);
    set_label_address("test", 34);
    Address* a = addr_from_label(strdup("test"));
    resolve_address(a);
    TEST_ASSERT_EQUAL_INT_MESSAGE(34, a->immediate, "Incorrect label address");
    free(a);
    free(i);
}
Ejemplo n.º 9
0
void test_ONFI_ReadParameterPage_ShouldRead_ONFI(void)
{
    static const int8_t expected[] = "ONFI";

    uint8_t buff[5];
    buff[4] = 0;

    ONFI_ReadParameterPage(0);
    ONFI_receive8(buff, 4);

    TEST_ASSERT_EQUAL_STRING(expected, buff);
}
Ejemplo n.º 10
0
void test_requestbuilder_BuildsWithContentLengthHeader(void)
{
    builder.writeToBuffer(requestBuffer, 512, true);
    TEST_ASSERT_EQUAL_STRING(
        "GET / HTTP/1.1\r\n"
        "Host: www.example.com\r\n"
        "Content-Type: text/html\r\n"
        "Some-Other-Header: Some-Other-Value\r\n"
        "Content-Length: 30\r\n"
        "\r\n"
        "This is some data in the body.\r\n", requestBuffer);
}
Ejemplo n.º 11
0
static void test_ipv6_addr_to_str__success5(void)
{
    ng_ipv6_addr_t a = { {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0xff, 0xff, 192, 168, 0, 1
        }
    };
    char result[NG_IPV6_ADDR_MAX_STR_LEN];

    TEST_ASSERT_EQUAL_STRING("::ffff:192.168.0.1",
                             ng_ipv6_addr_to_str(result, &a, sizeof(result)));
}
Ejemplo n.º 12
0
static void test_fmt_lpad(void)
{
    const char base[] = "abcd";
    char string[9] = {0};

    strcpy(string, base);

    fmt_lpad(string, 4, 8, ' ');

    TEST_ASSERT_EQUAL_STRING("    abcd", (char*)string);

    fmt_lpad(string, 0, 0, '1');

    TEST_ASSERT_EQUAL_STRING("    abcd", (char*)string);

    fmt_lpad(string, 4, 0, '2');

    TEST_ASSERT_EQUAL_STRING("    abcd", (char*)string);

    fmt_lpad(string, 0, 4, '3');

    TEST_ASSERT_EQUAL_STRING("3333abcd", (char*)string);

    fmt_lpad(string, 8, 8, '4');

    TEST_ASSERT_EQUAL_STRING("3333abcd", (char*)string);

    fmt_lpad(string, 4, 8, 'x');

    TEST_ASSERT_EQUAL_STRING((char*)string, "xxxx3333");
}
Ejemplo n.º 13
0
void test_getSection(void)
{
   char* content = " echo \"\
[TcpClient] \n\
LogicName   = tcpClient1 \n\
DestIp      = 127.0.0.1 \n\
DestPort    = 1111 \n\
LocalPort   = 8888 \n\
\n\
[TcpClient] \n\
LogicName   = tcpClient2 \n\
DestIp      = 127.0.0.1 \n\
DestPort    = 2222 \n\
LocalPort   = 9999 \n\
\n\
[TcpClient] \n\
LogicName   = tcpClient3 \n\
DestIp      = 127.0.0.1 \n\
DestPort    = 3333 \n\
LocalPort   = 1234 \n\"        > commModule.conf";
   system(content);
   char section[MAX_LEN_SECTION] = {0};
   int ret = getSection("./commModule.conf", 0, "TcpClient", section);
   TEST_ASSERT_EQUAL_INT(3, ret);

   memset(section, 0, MAX_LEN_SECTION);
   ret = getSection("./commModule.conf", 1, "TcpClient", section);
   TEST_ASSERT_EQUAL_INT(TOOLS_SUCCESS, ret);
   TEST_ASSERT_EQUAL_STRING("[TcpClient] \nLogicName   = tcpClient1 \nDestIp      = 127.0.0.1 \nDestPort    = 1111 \nLocalPort   = 8888 \n\n", section);

   memset(section, 0, MAX_LEN_SECTION);
   ret = getSection("./commModule.conf", 2, "TcpClient", section);
   TEST_ASSERT_EQUAL_INT(TOOLS_SUCCESS, ret);
   TEST_ASSERT_EQUAL_STRING("[TcpClient] \nLogicName   = tcpClient2 \nDestIp      = 127.0.0.1 \nDestPort    = 2222 \nLocalPort   = 9999 \n\n", section);

   memset(section, 0, MAX_LEN_SECTION);
   ret = getSection("./commModule.conf", 3, "TcpClient", section);
   TEST_ASSERT_EQUAL_INT(TOOLS_SUCCESS, ret);
   TEST_ASSERT_EQUAL_STRING("[TcpClient] \nLogicName   = tcpClient3 \nDestIp      = 127.0.0.1 \nDestPort    = 3333 \nLocalPort   = 1234 \n\n", section);
}
Ejemplo n.º 14
0
void test_MultipleEntryHandling() {
	char HOST1[] = "192.0.2.3";
	char REASON1[] = "DENY";

	char HOST2[] = "192.0.5.5";
	char REASON2[] = "RATE";

	char HOST3[] = "192.0.10.1";
	char REASON3[] = "DENY";

	add_entry(HOST1, REASON1);
	add_entry(HOST2, REASON2);
	add_entry(HOST3, REASON3);

	struct kod_entry* result;

	TEST_ASSERT_EQUAL(1, search_entry(HOST1, &result));
	TEST_ASSERT_EQUAL_STRING(HOST1, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON1, result->type);

	TEST_ASSERT_EQUAL(1, search_entry(HOST2, &result));
	TEST_ASSERT_EQUAL_STRING(HOST2, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON2, result->type);

	TEST_ASSERT_EQUAL(1, search_entry(HOST3, &result));
	TEST_ASSERT_EQUAL_STRING(HOST3, result->hostname);
	TEST_ASSERT_EQUAL_STRING(REASON3, result->type);

	free(result);
}
Ejemplo n.º 15
0
void test_convertBasedNumberToBase10Number_will_throw_error_when_a_symbol_inside_the_hexadecimal_expression_star_with_0x()
{
	String testTokenizer;
	String *testTokenizer1;
	Error exception;
	testTokenizer.rawString = "0x1@00";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 6;
	//Since it is work , c whether work for other symbol
	Try
	{
		testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	}
	Catch(exception)
	{
		TEST_ASSERT_EQUAL(INVALID_EXPRESSION,exception);
		
		// Check the error message been updated or not . 
		TEST_ASSERT_EQUAL_STRING("0x1@00",errorMessage.rawString);
		TEST_ASSERT_EQUAL(3,errorMessage.position);
		TEST_ASSERT_EQUAL_STRING("Invalid expression ! ",errorMessage.message);
		
	}
	
	testTokenizer.rawString = "0x1$00";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 6;
	Try
	{
		testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	}
	Catch(exception)
	{
		TEST_ASSERT_EQUAL(INVALID_EXPRESSION,exception);
		
		// Check the error message been updated or not . 
		TEST_ASSERT_EQUAL_STRING("0x1$00",errorMessage.rawString);
		TEST_ASSERT_EQUAL(3,errorMessage.position);
		TEST_ASSERT_EQUAL_STRING("Invalid expression ! ",errorMessage.message);
		
	}
	
	testTokenizer.rawString = "0x1=00";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 6;
	Try
	{
		testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	}
	Catch(exception)
	{
		TEST_ASSERT_EQUAL(INVALID_EXPRESSION,exception);
		
		// Check the error message been updated or not . 
		TEST_ASSERT_EQUAL_STRING("0x1=00",errorMessage.rawString);
		TEST_ASSERT_EQUAL(3,errorMessage.position);
		TEST_ASSERT_EQUAL_STRING("Invalid expression ! ",errorMessage.message);
		
	}
}
Ejemplo n.º 16
0
static void testnosepfullname(void)
{
	Person_setFullName(personRef, "sample");

	TEST_ASSERT_EQUAL_STRING("sample", Person_fullName(personRef));
	TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef));
	TEST_ASSERT_EQUAL_STRING("", Person_lastName(personRef));

	Person_setLastName(personRef, "tarou");
	TEST_ASSERT_EQUAL_STRING("sample tarou", Person_fullName(personRef));
	TEST_ASSERT_EQUAL_STRING("sample", Person_firstName(personRef));
	TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef));

	Person_setFirstName(personRef, "test");
	TEST_ASSERT_EQUAL_STRING("test tarou", Person_fullName(personRef));
	TEST_ASSERT_EQUAL_STRING("test", Person_firstName(personRef));
	TEST_ASSERT_EQUAL_STRING("tarou", Person_lastName(personRef));
}
Ejemplo n.º 17
0
TEST(socktoa, IPv6AddressWithPort) {
	const struct in6_addr address = {{{
		0x20, 0x01, 0x0d, 0xb8,
		0x85, 0xa3, 0x08, 0xd3,
		0x13, 0x19, 0x8a, 0x2e,
		0x03, 0x70, 0x73, 0x34
	}}};

	const char* expected =
		"2001:db8:85a3:8d3:1319:8a2e:370:7334";
	const char* expected_port = 
		"[2001:db8:85a3:8d3:1319:8a2e:370:7334]:123";

	sockaddr_u input;
	memset(&input, 0, sizeof(input));
	AF(&input) = AF_INET6;
	SET_ADDR6N(&input, address);
	SET_PORT(&input, 123);

	TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input));
	TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
}
Ejemplo n.º 18
0
void test_format_results() {
    ClientFunctionRegistryEntry f = lookupClientFunction("test_read_value");
    TEST_ASSERT_NOT_NULL(f);
    TEST_ASSERT_NOT_NULL(f->format_results);

    int16_t res;
    test_write_value(test_device, 4500);
    test_read_value(test_device, &res);

    init_mock_printf();
    f->format_results(mock_printf, &res, sizeof(res));
    TEST_ASSERT_EQUAL_STRING("Test value: 4500", mock_printf_buffer);
}
void test_convertBasedNumberToBase10Number_will_convert_the_number_if_it_is_inside_expression()
{
	String testTokenizer;
	String *testTokenizer1;
	testTokenizer.rawString = "0x1234+12";
	testTokenizer.startIndex = 0;
	testTokenizer.length = 9;
	testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	TEST_ASSERT_EQUAL_STRING("4660+12",testTokenizer1->rawString);
	TEST_ASSERT_EQUAL(0,testTokenizer1->startIndex);
	TEST_ASSERT_EQUAL(7,testTokenizer1->length);
	free(testTokenizer1);
}
Ejemplo n.º 20
0
void test_renameCompressedFile_given_object_dot_o_should_rename_to_object_dot_o()
{
    char *CompressedName;
    char *InfileName = "object.o" ;
    
    CompressedName = calloc(strlen(InfileName)+4,sizeof(char));
    
    renameCompressedFile(InfileName,CompressedName,Fixed);
    
    TEST_ASSERT_EQUAL_STRING("object.LZ",CompressedName);
    
    free(CompressedName);
}
Ejemplo n.º 21
0
void test_renameCompressedFile_given_noname_should_rename_to_noname_dot_LZ()
{
    char *CompressedName;
    char *InfileName = "noname" ;
    
    CompressedName = calloc(strlen(InfileName)+4,sizeof(char));
    
    renameCompressedFile(InfileName,CompressedName,Fixed);
    
    TEST_ASSERT_EQUAL_STRING("noname.LZ",CompressedName);
    
    free(CompressedName);
}
Ejemplo n.º 22
0
void test_renameCompressedFile_given_Variable_mode_at_Source_should_change_to_Compressed_Variable()
{
    char *CompressedName;
    char *InfileName = "test/support/Source/test_LZ78_CompressorDecompressor.txt" ;
    
    CompressedName = calloc(strlen(InfileName)+20,sizeof(char));
    
    renameCompressedFile(InfileName,CompressedName,Variable);
    
    TEST_ASSERT_EQUAL_STRING("test/support/Compressed/Variable/test_LZ78_CompressorDecompressor.LZ",CompressedName);
    
    free(CompressedName);
}
Ejemplo n.º 23
0
void test_KineticSession_Connect_should_report_a_failed_connection(void)
{
    TEST_ASSERT_EQUAL_STRING(Session.config.host, "somehost.com");
    TEST_ASSERT_EQUAL(17, Session.config.port);

    KineticSocket_Connect_ExpectAndReturn("somehost.com", 17, KINETIC_SOCKET_DESCRIPTOR_INVALID);

    KineticStatus status = KineticSession_Connect(&Session);

    TEST_ASSERT_EQUAL(KINETIC_STATUS_CONNECTION_ERROR, status);
    TEST_ASSERT_FALSE(Session.connected);
    TEST_ASSERT_EQUAL(KINETIC_SOCKET_DESCRIPTOR_INVALID, Session.socket);
}
void test_convertBasedNumberToBase10Number_will_convert_the_hexadecimal_number_if_it_is_inside_expression()
{
	String testTokenizer;
	String *testTokenizer1;
	testTokenizer.rawString = "12+h'1234'";
	testTokenizer.startIndex = 3;
	testTokenizer.length = 10;
	testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	TEST_ASSERT_EQUAL_STRING("12+4660",testTokenizer1->rawString);
	TEST_ASSERT_EQUAL(3,testTokenizer1->startIndex);
	TEST_ASSERT_EQUAL(7,testTokenizer1->length);
	free(testTokenizer1);
}
Ejemplo n.º 25
0
static void test_pktbuf_add__pkt_NOT_NULL__data_NOT_NULL__size_not_0(void)
{
    ng_pktsnip_t *pkt, *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4),
                               NG_NETTYPE_UNDEF);

    TEST_ASSERT_NOT_NULL(next);

    TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, TEST_STRING8, sizeof(TEST_STRING8),
                                NG_NETTYPE_UNDEF)));

    TEST_ASSERT(pkt->next == next);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING8, pkt->data);
    TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size);
    TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type);

    TEST_ASSERT_NULL(next->next);
    TEST_ASSERT_EQUAL_STRING(TEST_STRING4, next->data);
    TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), next->size);
    TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type);

    TEST_ASSERT(!ng_pktbuf_is_empty());
}
void test_convertBasedNumberToBase10Number_will_convert_the_hexadecimal_number_if_it_is_middle_of_the_expression()
{
	String testTokenizer;
	String *testTokenizer1;
	testTokenizer.rawString = "12+o'226'*128";
	testTokenizer.startIndex = 3;
	testTokenizer.length = 13;
	testTokenizer1 = convertBasedNumberToBase10Number(&testTokenizer);
	TEST_ASSERT_EQUAL_STRING("12+150*128",testTokenizer1->rawString);
	TEST_ASSERT_EQUAL(3,testTokenizer1->startIndex);
	TEST_ASSERT_EQUAL(10,testTokenizer1->length);
	free(testTokenizer1);
}
Ejemplo n.º 27
0
void test_responseparser_ReadsHTTPHeaders(void)
{
    char response[] = 
        "HTTP/1.0 200 OK\r\n"
        "Content-Length:100\r\n"
        "Some-Other-Header: Some-Other-Value\r\n";

    ResponseParser responseParser(response);

    char headerNames[][20] = {"Content-Length", "Some-Other-Header"};
    char headerValues[][20] = {"100", "Some-Other-Value"};

    TEST_ASSERT_EQUAL(2, responseParser.headerCount());
    TEST_ASSERT_NOT_NULL(responseParser.findHeaderInList(headerNames[0]));
    TEST_ASSERT_NOT_NULL(responseParser.findHeaderInList(headerNames[1]));

    TEST_ASSERT_EQUAL_PTR(responseParser.getHeaderByIndex(0), responseParser.findHeaderInList(headerNames[0]));
    TEST_ASSERT_EQUAL_PTR(responseParser.getHeaderByIndex(1), responseParser.findHeaderInList(headerNames[1]));
    
    TEST_ASSERT_EQUAL_STRING(headerValues[0], responseParser.getHeaderValue(headerNames[0]));
    TEST_ASSERT_EQUAL_STRING(headerValues[1], responseParser.getHeaderValue(headerNames[1]));
}
Ejemplo n.º 28
0
void test_lzwDecode_given_code_98_97_110_should_decode_into_ban(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(100);
  OutStream out;
  InStream in;
   
  streamReadBits_ExpectAndReturn(&in, 8, 98);
  streamWriteBits_Expect(&out, 98, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 97);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 110);
  streamWriteBits_Expect(&out, 110, 8);
  streamReadBits_ExpectAndReturn(&in, 9, -1);
  
  Try{
    lzwDecode(&in, dictionary, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
    TEST_ASSERT_EQUAL_STRING("ba", dictionary->entries[0].code);
    TEST_ASSERT_EQUAL_STRING("an", dictionary->entries[1].code);
  }
}
Ejemplo n.º 29
0
TEST(fs, ReadWriteShouldComplete)
{
	cnmkfs();
	cnmount();
	cnmkdir("test1");
	cncd("test1");
	dir_ptr* dir = cnopendir(".");
	int16_t fd1 = cnopen(dir, "file1.txt", FD_WRITE);
	cnseek(fd1, 10000);
	size_t bytes_written = cnwrite((uint8_t*)"This is only a test.", 21, fd1);
	cnseek(fd1, 20000);
	bytes_written = cnwrite((uint8_t*)"This is only a test.", 21, fd1);
	cnseek(fd1, 50000);
	bytes_written = cnwrite((uint8_t*)"This is only a test.", 21, fd1);
	cnseek(fd1, 40000);
	bytes_written = cnwrite((uint8_t*)"This is only a test.", 21, fd1);
	cnclose(fd1);
	system("hd /tmp/fs.bin");
	TEST_ASSERT_TRUE(21 == bytes_written);
	char readbuf[100];
	fd1 = cnopen(dir, "file1.txt", FD_READ);
	cnseek(fd1, 50000);
	size_t bytes_read = cnread((uint8_t*)readbuf, 21, fd1);
	TEST_ASSERT_EQUAL_STRING("This is only a test.", readbuf);
	TEST_ASSERT_TRUE(21 == bytes_read);
	cnseek(fd1, 20000);
	bytes_read = cnread((uint8_t*)readbuf, 21, fd1);
	TEST_ASSERT_EQUAL_STRING("This is only a test.", readbuf);
	TEST_ASSERT_TRUE(21 == bytes_read);
	cnseek(fd1, 10000);
	bytes_read = cnread((uint8_t*)readbuf, 21, fd1);
	TEST_ASSERT_EQUAL_STRING("This is only a test.", readbuf);
	TEST_ASSERT_TRUE(21 == bytes_read);
	cnseek(fd1, 40000);
	bytes_read = cnread((uint8_t*)readbuf, 21, fd1);
	TEST_ASSERT_EQUAL_STRING("This is only a test.", readbuf);
	TEST_ASSERT_TRUE(21 == bytes_read);
	cnumount();
}
Ejemplo n.º 30
0
Archivo: msyslog.c Proyecto: Darge/ntp
void
test_msnprintfTruncate(void) {
	char	undist[] = "undisturbed";
	char	exp_buf[512];
	char	act_buf[512];
	int	exp_cnt;
	int	act_cnt;

	memcpy(exp_buf + 3, undist, sizeof(undist));
	memcpy(act_buf + 3, undist, sizeof(undist));
	exp_cnt = snprintf(exp_buf, 3, "%s", strerror(ENOENT));
	errno = ENOENT;
	act_cnt = msnprintf(act_buf, 3, "%m");

	TEST_ASSERT_EQUAL('\0', exp_buf[2]);
	TEST_ASSERT_EQUAL('\0', act_buf[2]);
	TEST_ASSERT_TRUE(act_cnt > 0);
	TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
	TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
	TEST_ASSERT_EQUAL_STRING(exp_buf + 3, undist);
	TEST_ASSERT_EQUAL_STRING(act_buf + 3, undist);
}