END_TEST #endif START_TEST (test_recv_edp) { char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65, 0x30, 0x35, 0x30, 0x31, 0x73, 0x77, 0x2e, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec, 0xff, 0xff, 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00, 0x00, 0x02, 0x80, 0xa5, 0x67, 0x20, 0xee, 0xee, 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x99, 0x00, 0x00, 0x04 }; /* This is: IEEE 802.3 Ethernet Destination: Extreme-EDP (00:e0:2b:00:00:00) Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) Length: 324 Logical-Link Control DSAP: SNAP (0xaa) IG Bit: Individual SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) 000. 00.. = Command: Unnumbered Information (0x00) .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Extreme Networks (0x00e02b) PID: EDP (0x00bb) Extreme Discovery Protocol Version: 1 Reserved: 0 Data length: 316 Checksum: 0xdf05 [correct] [Good: True] [Bad : False] Sequence number: 783 Machine ID type: MAC (0) Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f) Info: Slot/Port: 1/1, Version: 7.6.4.0 Marker 0x99, length 36, type 2 = Info TLV Marker: 0x99 TLV type: Info (2) TLV length: 36 Slot: 1 Port: 1 Virt chassis: 0 Reserved: 000000000000 Version: 7.6.4 Internal: 0 Version: 0x07060400 Version (major1): 7 Version (major2): 6 Version (sustaining): 4 Version (internal): 0 Connections: FFFF0000000000000000000000000000 Display: "ne0501sw.XXXXXX" Marker 0x99, length 260, type 1 = Display TLV Marker: 0x99 TLV type: Display (1) TLV length: 260 Name: ne0501sw.XXXXXX Null Marker 0x99, length 4, type 0 = Null TLV Marker: 0x99 TLV type: Null (0) TLV length: 4 */ #ifdef ENABLE_DOT1 char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x43, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x61, 0x76, 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76, 0x20, 0x28, 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75, 0x70, 0x65, 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x20, 0x25, 0x64, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61, 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; /* This is: IEEE 802.3 Ethernet Destination: Extreme-EDP (00:e0:2b:00:00:00) Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) Length: 328 Logical-Link Control DSAP: SNAP (0xaa) IG Bit: Individual SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) 000. 00.. = Command: Unnumbered Information (0x00) .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Extreme Networks (0x00e02b) PID: EDP (0x00bb) Extreme Discovery Protocol Version: 1 Reserved: 0 Data length: 320 Checksum: 0x7304 [correct] [Good: True] [Bad : False] Sequence number: 784 Machine ID type: MAC (0) Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f) Vlan: ID 1, Name "Default" Marker 0x99, length 100, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 100 Flags: 0x80 1... .... = Flags-IP: Set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 1 Reserved2: 00000000 IP addr: 0.0.0.0 (0.0.0.0) Name: Default Vlan: ID 0, Name "MacVlanDiscover" Marker 0x99, length 100, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 100 Flags: 0x00 0... .... = Flags-IP: Not set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 0 Reserved2: 00000000 IP addr: 0.0.0.0 (0.0.0.0) Name: MacVlanDiscover Vlan: ID 50, Name "AdminB2" Marker 0x99, length 100, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 100 Flags: 0x80 1... .... = Flags-IP: Set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 50 Reserved2: 00000000 IP addr: 10.50.0.63 (10.50.0.63) Name: AdminB2 Null Marker 0x99, length 4, type 0 = Null TLV Marker: 0x99 TLV type: Null (0) TLV length: 4 */ struct lldpd_vlan *vlan; #endif struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; struct lldpd cfg; char mac1[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f }; cfg.g_mgmt_pattern = NULL; fail_unless(edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LLADDR); ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN); fail_unless(memcmp(nchassis->c_id, mac1, ETH_ALEN) == 0); ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_IFNAME); ck_assert_int_eq(nport->p_id_len, strlen("1/1")); fail_unless(memcmp(nport->p_id, "1/1", strlen("1/1")) == 0); ck_assert_str_eq(nport->p_descr, "Slot 1 / Port 1"); ck_assert_str_eq(nchassis->c_name, "ne0501sw.XXXXXX"); ck_assert_str_eq(nchassis->c_descr, "EDP enabled device, version 7.6.4.0"); ck_assert_int_eq(nchassis->c_cap_enabled, 0); #ifdef ENABLE_DOT1 /* Add this port to list of remote port for hardware port */ TAILQ_INSERT_TAIL(&hardware.h_rports, nport, p_entries); nport->p_chassis = nchassis; nport->p_protocol = LLDPD_MODE_EDP; /* Recept second packet */ nchassis = NULL; nport = NULL; fail_unless(edp_decode(&cfg, pkt2, sizeof(pkt2), &hardware, &nchassis, &nport) == -1); nport = TAILQ_FIRST(&hardware.h_rports); if (!nport) { fail("unable to find our previous port?"); return; } ck_assert_int_eq(TAILQ_FIRST(&nport->p_chassis->c_mgmt)->m_addr.inet.s_addr, (u_int32_t)inet_addr("10.50.0.63")); if (TAILQ_EMPTY(&nport->p_vlans)) { fail("no VLAN"); return; } vlan = TAILQ_FIRST(&nport->p_vlans); ck_assert_int_eq(vlan->v_vid, 1); ck_assert_str_eq(vlan->v_name, "Default"); vlan = TAILQ_NEXT(vlan, v_entries); if (!vlan) { fail("no more VLAN"); return; } ck_assert_int_eq(vlan->v_vid, 0); ck_assert_str_eq(vlan->v_name, "MacVlanDiscover"); vlan = TAILQ_NEXT(vlan, v_entries); if (!vlan) { fail("no more VLAN"); return; } ck_assert_int_eq(vlan->v_vid, 50); ck_assert_str_eq(vlan->v_name, "AdminB2"); vlan = TAILQ_NEXT(vlan, v_entries); fail_unless(vlan == NULL); #endif }
END_TEST START_TEST (test_roman_digit_check_individual_error) { char tst_str[2]; char tst_ch; tst_str[1]=0; for(tst_ch = 1; tst_ch <= 'B'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'E'; tst_ch <= 'H'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'J'; tst_ch <= 'K'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'N'; tst_ch <= 'U'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } ck_assert_int_eq (rnum_check ("W"), RNUM_ERR_INPUT_NON_NUMERAL); for(tst_ch = 'Y'; tst_ch <= 'b'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'e'; tst_ch <= 'h'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'j'; tst_ch <= 'k'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } for(tst_ch = 'n'; tst_ch <= 'u'; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } ck_assert_int_eq (rnum_check ("w"), RNUM_ERR_INPUT_NON_NUMERAL); for(tst_ch = 'y'; tst_ch <= 126; tst_ch++){ *tst_str = tst_ch; ck_assert_int_eq (rnum_check (tst_str), RNUM_ERR_INPUT_NON_NUMERAL); } }
END_TEST START_TEST(test_mg_server_and_client_tls) { #ifndef NO_SSL struct mg_context *ctx; int ports_cnt; struct mg_server_ports ports[16]; struct mg_callbacks callbacks; char errmsg[256]; struct mg_connection *client_conn; char client_err[256]; const struct mg_request_info *client_ri; int client_res; struct mg_client_options client_options; const char *OPTIONS[32]; /* initializer list here is rejected by CI test */ int opt_idx = 0; char server_cert[256]; char client_cert[256]; const char *res_dir = locate_resources(); ck_assert(res_dir != NULL); strcpy(server_cert, res_dir); strcpy(client_cert, res_dir); #ifdef _WIN32 strcat(server_cert, "cert\\server.pem"); strcat(client_cert, "cert\\client.pem"); #else strcat(server_cert, "cert/server.pem"); strcat(client_cert, "cert/client.pem"); #endif memset((void *)OPTIONS, 0, sizeof(OPTIONS)); #if !defined(NO_FILES) OPTIONS[opt_idx++] = "document_root"; OPTIONS[opt_idx++] = "."; #endif OPTIONS[opt_idx++] = "listening_ports"; OPTIONS[opt_idx++] = "8080r,8443s"; OPTIONS[opt_idx++] = "ssl_certificate"; OPTIONS[opt_idx++] = server_cert; OPTIONS[opt_idx++] = "ssl_verify_peer"; OPTIONS[opt_idx++] = "yes"; OPTIONS[opt_idx++] = "ssl_ca_file"; OPTIONS[opt_idx++] = client_cert; ck_assert_int_le(opt_idx, (int)(sizeof(OPTIONS) / sizeof(OPTIONS[0]))); ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 1] == NULL); ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 2] == NULL); memset(ports, 0, sizeof(ports)); memset(&callbacks, 0, sizeof(callbacks)); memset(errmsg, 0, sizeof(errmsg)); callbacks.log_message = log_msg_func; ctx = mg_start(&callbacks, (void *)errmsg, OPTIONS); test_sleep(1); ck_assert_str_eq(errmsg, ""); ck_assert(ctx != NULL); ports_cnt = mg_get_server_ports(ctx, 16, ports); ck_assert_int_eq(ports_cnt, 2); ck_assert_int_eq(ports[0].protocol, 1); ck_assert_int_eq(ports[0].port, 8080); ck_assert_int_eq(ports[0].is_ssl, 0); ck_assert_int_eq(ports[0].is_redirect, 1); ck_assert_int_eq(ports[1].protocol, 1); ck_assert_int_eq(ports[1].port, 8443); ck_assert_int_eq(ports[1].is_ssl, 1); ck_assert_int_eq(ports[1].is_redirect, 0); ck_assert_int_eq(ports[2].protocol, 0); ck_assert_int_eq(ports[2].port, 0); ck_assert_int_eq(ports[2].is_ssl, 0); ck_assert_int_eq(ports[2].is_redirect, 0); test_sleep(1); memset(client_err, 0, sizeof(client_err)); client_conn = mg_connect_client("127.0.0.1", 8443, 1, client_err, sizeof(client_err)); ck_assert(client_conn == NULL); ck_assert_str_ne(client_err, ""); memset(client_err, 0, sizeof(client_err)); memset(&client_options, 0, sizeof(client_options)); client_options.host = "127.0.0.1"; client_options.port = 8443; client_options.client_cert = client_cert; client_options.server_cert = server_cert; client_conn = mg_connect_client_secure(&client_options, client_err, sizeof(client_err)); ck_assert(client_conn != NULL); ck_assert_str_eq(client_err, ""); mg_printf(client_conn, "GET / HTTP/1.0\r\n\r\n"); client_res = mg_get_response(client_conn, client_err, sizeof(client_err), 10000); ck_assert_int_ge(client_res, 0); ck_assert_str_eq(client_err, ""); client_ri = mg_get_request_info(client_conn); ck_assert(client_ri != NULL); #if defined(NO_FILES) ck_assert_str_eq(client_ri->uri, "404"); #else ck_assert_str_eq(client_ri->uri, "200"); /* TODO: ck_assert_str_eq(client_ri->request_method, "HTTP/1.0"); */ client_res = (int)mg_read(client_conn, client_err, sizeof(client_err)); ck_assert_int_gt(client_res, 0); ck_assert_int_le(client_res, sizeof(client_err)); #endif mg_close_connection(client_conn); /* TODO: A client API using a client certificate is missing */ test_sleep(1); mg_stop(ctx); #endif }
END_SETUP START_TEARDOWN(teardown_destroy_data) { ck_assert_int_eq(destroy_data_called, 1); }
END_TEST START_TEST(test_peer_split_host) { char * host; int port; ck_assert_int_eq(peer_split_host("localhost:8000", &host, &port), RET_OK); ck_assert_int_eq(port, 8000); ck_assert(host != NULL); ck_assert_str_eq(host, "localhost"); ck_assert_int_eq(peer_split_host("*:8000", &host, &port), RET_OK); ck_assert_int_eq(port, 8000); ck_assert(host == NULL); ck_assert_int_eq(peer_split_host(":8000", &host, &port), RET_OK); ck_assert_int_eq(port, 8000); ck_assert(host == NULL); ck_assert_int_eq(peer_split_host("8000", &host, &port), RET_OK); ck_assert_int_eq(port, 8000); ck_assert(host == NULL); ck_assert_int_eq(peer_split_host("8000localhost", &host, &port), RET_PEER_RESOLVE_ERROR); ck_assert_int_eq(peer_split_host("localhost", &host, &port), RET_PEER_RESOLVE_ERROR); ck_assert_int_eq(peer_split_host("localhost:http", &host, &port), RET_PEER_RESOLVE_ERROR); }
END_TEST START_TEST(test_mg_get_var) { char buf[32]; int ret; const char *shortquery = "key1=1&key2=2&key3=3"; const char *longquery = "key1=1&key2=2&key3&key4=4&key5=&key6&" "key7=this+is+it&key8=8&key9&&key10=&&" "key7=that+is+it&key12=12"; /* invalid result buffer */ ret = mg_get_var2("", 0, "notfound", NULL, 999, 0); ck_assert_int_eq(ret, -2); /* zero size result buffer */ ret = mg_get_var2("", 0, "notfound", buf, 0, 0); ck_assert_int_eq(ret, -2); /* too small result buffer */ ret = mg_get_var2("key=toooooooooolong", 19, "key", buf, 4, 0); /* ck_assert_int_eq(ret, -3); --> TODO: mg_get_cookie returns -3, mg_get_var -2. This should be unified. */ ck_assert(ret < 0); /* key not found in string */ ret = mg_get_var2("", 0, "notfound", buf, sizeof(buf), 0); ck_assert_int_eq(ret, -1); ret = mg_get_var2( longquery, strlen(longquery), "notfound", buf, sizeof(buf), 0); ck_assert_int_eq(ret, -1); /* key not found in string */ ret = mg_get_var2( shortquery, strlen(shortquery), "notfound", buf, sizeof(buf), 0); ck_assert_int_eq(ret, -1); /* key not found in string */ ret = mg_get_var2("key1=1&key2=2&key3=3¬found=here", strlen(shortquery), "notfound", buf, sizeof(buf), 0); ck_assert_int_eq(ret, -1); /* key not found in string */ ret = mg_get_var2( shortquery, strlen(shortquery), "key1", buf, sizeof(buf), 1); ck_assert_int_eq(ret, -1); /* keys are found as first, middle and last key */ memset(buf, 77, sizeof(buf)); ret = mg_get_var2( shortquery, strlen(shortquery), "key1", buf, sizeof(buf), 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq("1", buf); memset(buf, 77, sizeof(buf)); ret = mg_get_var2( shortquery, strlen(shortquery), "key2", buf, sizeof(buf), 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq("2", buf); memset(buf, 77, sizeof(buf)); ret = mg_get_var2( shortquery, strlen(shortquery), "key3", buf, sizeof(buf), 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq("3", buf); /* longer value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_var2(longquery, strlen(longquery), "key7", buf, sizeof(buf), 0); ck_assert_int_eq(ret, 10); ck_assert_str_eq("this is it", buf); /* longer value in the middle of a longer string - seccond occurance of key */ memset(buf, 77, sizeof(buf)); ret = mg_get_var2(longquery, strlen(longquery), "key7", buf, sizeof(buf), 1); ck_assert_int_eq(ret, 10); ck_assert_str_eq("that is it", buf); /* key with = but without value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_var2(longquery, strlen(longquery), "key5", buf, sizeof(buf), 0); ck_assert_int_eq(ret, 0); ck_assert_str_eq(buf, ""); /* key without = and without value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_var2(longquery, strlen(longquery), "key6", buf, sizeof(buf), 0); ck_assert_int_eq(ret, -1); ck_assert_str_eq(buf, ""); /* TODO: this is the same situation as with mg_get_value */ }
END_TEST START_TEST(test_basic_broadcast) { GpuArray a; GpuArray b; GpuArray c; GpuElemwise *ge; static const uint32_t data1[3] = {1, 2, 3}; static const uint32_t data2[2] = {4, 5}; uint32_t data3[6] = {0}; size_t dims[2]; gpuelemwise_arg args[3] = {{0}}; void *rargs[3]; dims[0] = 1; dims[1] = 3; ga_assert_ok(GpuArray_empty(&a, ctx, GA_UINT, 2, dims, GA_C_ORDER)); ga_assert_ok(GpuArray_write(&a, data1, sizeof(data1))); dims[0] = 2; dims[1] = 1; ga_assert_ok(GpuArray_empty(&b, ctx, GA_UINT, 2, dims, GA_F_ORDER)); ga_assert_ok(GpuArray_write(&b, data2, sizeof(data2))); dims[0] = 2; dims[1] = 3; ga_assert_ok(GpuArray_empty(&c, ctx, GA_UINT, 2, dims, GA_C_ORDER)); args[0].name = "a"; args[0].typecode = GA_UINT; args[0].flags = GE_READ; args[1].name = "b"; args[1].typecode = GA_UINT; args[1].flags = GE_READ; args[2].name = "c"; args[2].typecode = GA_UINT; args[2].flags = GE_WRITE; ge = GpuElemwise_new(ctx, "", "c = a + b", 3, args, 2, 0); ck_assert_ptr_ne(ge, NULL); rargs[0] = &a; rargs[1] = &b; rargs[2] = &c; ck_assert_int_eq(GpuElemwise_call(ge, rargs, GE_NOCOLLAPSE), GA_VALUE_ERROR); ga_assert_ok(GpuElemwise_call(ge, rargs, GE_NOCOLLAPSE|GE_BROADCAST)); ga_assert_ok(GpuArray_read(data3, sizeof(data3), &c)); ck_assert_int_eq(data3[0], 5); ck_assert_int_eq(data3[1], 6); ck_assert_int_eq(data3[2], 7); ck_assert_int_eq(data3[3], 6); ck_assert_int_eq(data3[4], 7); ck_assert_int_eq(data3[5], 8); }
END_TEST // -------------------------------------------------------------------------- /// Try to _pop () multiple different values. START_TEST(test_msg_pop) { sam_selftest_introduce ("test_msg_pop"); zmsg_t *zmsg = zmsg_new (); // data to be pop()'d char *nbr = "17"; char *str = "test"; char a = 'a'; zframe_t *char_frame = zframe_new (&a, sizeof (a)); void *ptr = (void *) 0xbadc0de; // compose zmsg out of // a number (i) int rc = zmsg_pushstr (zmsg, nbr); ck_assert_int_eq (rc, 0); // a char * (s) rc = zmsg_pushstr (zmsg, str); ck_assert_int_eq (rc, 0); // a frame * (f) zframe_t *frame_dup = zframe_dup (char_frame); rc = zmsg_prepend (zmsg, &frame_dup); ck_assert_int_eq (rc, 0); // a void * (p) rc = zmsg_pushmem (zmsg, &ptr, sizeof (ptr)); ck_assert_int_eq (rc, 0); // values to be filled int pic_nbr; char *pic_str; zframe_t *pic_frame; void *pic_ptr; // create message sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 4); rc = sam_msg_pop (msg, "pfsi", &pic_ptr, &pic_frame, &pic_str, &pic_nbr); // test data ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 0); ck_assert (zframe_eq (char_frame, pic_frame)); ck_assert_int_eq (pic_nbr, atoi (nbr)); ck_assert_str_eq (pic_str, str); ck_assert_ptr_eq (pic_ptr, ptr); // clean up zframe_destroy (&char_frame); sam_msg_destroy (&msg); }
END_TEST // -------------------------------------------------------------------------- /// Try to _get () a combination of data. START_TEST(test_msg_get) { sam_selftest_introduce ("test_msg_get"); zmsg_t *zmsg = zmsg_new (); char *str = "str 1", *nbr = "1"; char c = 'a'; zframe_t *frame = zframe_new (&c, sizeof (c)); void *ptr = (void *) 0xbadc0de; zframe_t *ptr_f = zframe_new (&ptr, sizeof (ptr)); // compose zmsg zmsg_addstr (zmsg, str); zmsg_addstr (zmsg, nbr); zmsg_addstr (zmsg, "skipped"); zframe_t *frame_dup = zframe_dup (frame); zmsg_append (zmsg, &frame_dup); frame_dup = zframe_dup (ptr_f); zmsg_append (zmsg, &frame_dup); // create sam_msg sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 5); // test idempotent _get () int round_c; for (round_c = 0; round_c < 2; round_c++) { char *pic_str = NULL; int pic_nbr = -1; zframe_t *pic_frame = NULL; void *pic_ptr = NULL; int rc = sam_msg_get ( msg, "si?fp", &pic_str, &pic_nbr, &pic_frame, &pic_ptr); ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 5); ck_assert_str_eq (pic_str, str); ck_assert_int_eq (pic_nbr, atoi (nbr)); ck_assert (zframe_eq (pic_frame, frame)); ck_assert (pic_ptr == ptr); free (pic_str); zframe_destroy (&pic_frame); } zframe_destroy (&frame); zframe_destroy (&ptr_f); sam_msg_destroy (&msg); }
END_TEST START_TEST(test_tree_basics) { int seven = 7, one = 1, three = 3; ck_assert_int_eq(tree_size(tree), 0); ck_assert_int_eq(*(int *)tree_insert(tree, &seven, &seven), seven); ck_assert_int_eq(tree_size(tree), 1); ck_assert_int_eq(*(int *)tree_insert(tree, &one, &one), one); ck_assert_int_eq(tree_size(tree), 2); ck_assert_int_eq(*(int *)tree_insert(tree, &three, &three), three); ck_assert_int_eq(tree_size(tree), 3); ck_assert_int_eq(*(int *)tree_find(tree, &seven), seven); ck_assert_int_eq(*(int *)tree_find(tree, &one), one); ck_assert_int_eq(*(int *)tree_find(tree, &three), three); ck_assert_int_eq(*(int *)tree_delete(tree, &seven), seven); ck_assert_int_eq(tree_size(tree), 2); ck_assert_int_eq(*(int *)tree_delete(tree, &one), one); ck_assert_int_eq(tree_size(tree), 1); ck_assert_int_eq(*(int *)tree_delete(tree, &three), three); ck_assert_int_eq(tree_size(tree), 0); }
END_TEST START_TEST (test_txt_putch) { ck_assert_int_eq(0, ulcd_txt_putch(ulcd, '!')); }
/* Post-test hook. */ void teardown () { ck_assert_int_eq (fz_memusage (0), 0); }
/* Pre-test hook. */ void setup () { srand (time (0)); ck_assert_int_eq (fz_memusage (0), 0); }
END_TEST #ifdef ENABLE_DOT1 START_TEST (test_send_vlans) { int n; /* Packets we should build: Extreme Discovery Protocol Version: 1 Reserved: 0 Data length: 74 Checksum: 0xde20 [correct] [Good: True] [Bad : False] Sequence number: 2 Machine ID type: MAC (0) Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Display: "First chassis" Marker 0x99, length 18, type 1 = Display TLV Marker: 0x99 TLV type: Display (1) TLV length: 18 Name: First chassis Info: Slot/Port: 1/4, Version: 7.6.4.99 Marker 0x99, length 36, type 2 = Info TLV Marker: 0x99 TLV type: Info (2) TLV length: 36 Slot: 1 Port: 4 Virt chassis: 0 Reserved: 000000000000 Version: 7.6.4 Internal: 99 Version: 0x07060463 Version (major1): 7 Version (major2): 6 Version (sustaining): 4 Version (internal): 99 Connections: FFFFFFFF000000000000000000000000 Null Marker 0x99, length 4, type 0 = Null TLV Marker: 0x99 TLV type: Null (0) TLV length: 4 Extreme Discovery Protocol Version: 1 Reserved: 0 Data length: 102 Checksum: 0x28c4 [correct] [Good: True] [Bad : False] Sequence number: 3 Machine ID type: MAC (0) Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Vlan: ID 157, Name "First VLAN" Marker 0x99, length 27, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 27 Flags: 0x00 0... .... = Flags-IP: Not set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 157 Reserved2: 00000000 IP addr: 0.0.0.0 (0.0.0.0) Name: First VLAN Vlan: ID 1247, Name "Second VLAN" Marker 0x99, length 28, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 28 Flags: 0x00 0... .... = Flags-IP: Not set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 1247 Reserved2: 00000000 IP addr: 0.0.0.0 (0.0.0.0) Name: Second VLAN Vlan: ID 741, Name "Third VLAN" Marker 0x99, length 27, type 5 = VL TLV Marker: 0x99 TLV type: VL (5) TLV length: 27 Flags: 0x00 0... .... = Flags-IP: Not set .000 000. = Flags-reserved: 0x00 .... ...0 = Flags-Unknown: Not set Reserved1: 00 Vlan ID: 741 Reserved2: 00000000 IP addr: 0.0.0.0 (0.0.0.0) Name: Third VLAN Null Marker 0x99, length 4, type 0 = Null TLV Marker: 0x99 TLV type: Null (0) TLV length: 4 */ char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x04, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x00, 0x00, 0x04 }; struct packet *pkt; struct lldpd_vlan vlan1, vlan2, vlan3; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; hardware.h_lport.p_id = "Not used"; hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id); hardware.h_lport.p_descr = "Not used"; strcpy(hardware.h_ifname, "eth3"); hardware.h_ifindex = 4; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis.c_id = macaddress; chassis.c_id_len = ETH_ALEN; chassis.c_name = "First chassis"; vlan1.v_name = "First VLAN"; vlan1.v_vid = 157; vlan2.v_name = "Second VLAN"; vlan2.v_vid = 1247; vlan3.v_name = "Third VLAN"; vlan3.v_vid = 741; TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries); /* Build packet */ n = edp_send(NULL, &hardware); if (n != 0) { fail("unable to build packet"); return; } if (TAILQ_EMPTY(&pkts)) { fail("no packets sent"); return; } pkt = TAILQ_FIRST(&pkts); ck_assert_int_eq(pkt->size, sizeof(pkt1)); fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0); pkt = TAILQ_NEXT(pkt, next); if (!pkt) { fail("need one more packet"); return; } ck_assert_int_eq(pkt->size, sizeof(pkt2)); fail_unless(memcmp(pkt->data, pkt2, sizeof(pkt2)) == 0); fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than two packets sent"); }
static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c, void *data, size_t size) { struct qb_ipc_request_header *req_pt = (struct qb_ipc_request_header *)data; struct qb_ipc_response_header response = { 0, }; ssize_t res; if (req_pt->id == IPC_MSG_REQ_TX_RX) { response.size = sizeof(struct qb_ipc_response_header); response.id = IPC_MSG_RES_TX_RX; response.error = 0; res = qb_ipcs_response_send(c, &response, response.size); if (res < 0) { qb_perror(LOG_INFO, "qb_ipcs_response_send"); } else if (res != response.size) { qb_log(LOG_DEBUG, "qb_ipcs_response_send %zd != %d", res, response.size); } if (turn_on_fc) { qb_ipcs_request_rate_limit(s1, QB_IPCS_RATE_OFF); } } else if (req_pt->id == IPC_MSG_REQ_DISPATCH) { response.size = sizeof(struct qb_ipc_response_header); response.id = IPC_MSG_RES_DISPATCH; response.error = 0; res = qb_ipcs_event_send(c, &response, sizeof(response)); if (res < 0) { qb_perror(LOG_INFO, "qb_ipcs_event_send"); } } else if (req_pt->id == IPC_MSG_REQ_BULK_EVENTS) { int32_t m; int32_t num; struct qb_ipcs_connection_stats_2 *stats; uint32_t max_size = MAX_MSG_SIZE; response.size = sizeof(struct qb_ipc_response_header); response.error = 0; stats = qb_ipcs_connection_stats_get_2(c, QB_FALSE); num = stats->event_q_length; free(stats); /* crazy large message */ res = qb_ipcs_event_send(c, &response, max_size*10); ck_assert_int_eq(res, -EMSGSIZE); /* send one event before responding */ res = qb_ipcs_event_send(c, &response, sizeof(response)); ck_assert_int_eq(res, sizeof(response)); response.id++; /* There should be one more item in the event queue now. */ stats = qb_ipcs_connection_stats_get_2(c, QB_FALSE); ck_assert_int_eq(stats->event_q_length - num, 1); free(stats); /* send response */ response.id = IPC_MSG_RES_BULK_EVENTS; res = qb_ipcs_response_send(c, &response, response.size); ck_assert_int_eq(res, sizeof(response)); /* send the rest of the events after the response */ for (m = 1; m < num_bulk_events; m++) { res = qb_ipcs_event_send(c, &response, sizeof(response)); if (res == -EAGAIN || res == -ENOBUFS) { /* retry */ usleep(1000); m--; continue; } ck_assert_int_eq(res, sizeof(response)); response.id++; } } else if (req_pt->id == IPC_MSG_REQ_STRESS_EVENT) { struct { struct qb_ipc_response_header hdr __attribute__ ((aligned(8))); char data[GIANT_MSG_DATA_SIZE] __attribute__ ((aligned(8))); uint32_t sent_msgs __attribute__ ((aligned(8))); } __attribute__ ((aligned(8))) giant_event_send; int32_t m; response.size = sizeof(struct qb_ipc_response_header); response.error = 0; response.id = IPC_MSG_RES_STRESS_EVENT; res = qb_ipcs_response_send(c, &response, response.size); ck_assert_int_eq(res, sizeof(response)); giant_event_send.hdr.error = 0; giant_event_send.hdr.id = IPC_MSG_RES_STRESS_EVENT; for (m = 0; m < num_stress_events; m++) { size_t sent_len = sizeof(struct qb_ipc_response_header); if (((m+1) % 1000) == 0) { sent_len = sizeof(giant_event_send); giant_event_send.sent_msgs = m + 1; } giant_event_send.hdr.size = sent_len; res = qb_ipcs_event_send(c, &giant_event_send, sent_len); if (res < 0) { if (res == -EAGAIN || res == -ENOBUFS) { /* yield to the receive process */ usleep(1000); m--; continue; } else { qb_perror(LOG_DEBUG, "sending stress events"); ck_assert_int_eq(res, sent_len); } } else if (((m+1) % 1000) == 0) { qb_log(LOG_DEBUG, "SENT: %d stress events sent", m+1); } giant_event_send.hdr.id++; } } else if (req_pt->id == IPC_MSG_REQ_SERVER_FAIL) {
END_TEST START_TEST(base64_test_1padding) { //this is base64'd ASCII string "open62541!!" UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQxISE="); //assure that we allocate exactly 11 bytes ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 11); UA_Byte* decodedData = (UA_Byte*)malloc(UA_base64_getDecodedSize(&encodedString)); UA_base64_decode(&encodedString, decodedData); //check the string ck_assert_int_eq(decodedData[0], 'o'); ck_assert_int_eq(decodedData[1], 'p'); ck_assert_int_eq(decodedData[2], 'e'); ck_assert_int_eq(decodedData[3], 'n'); ck_assert_int_eq(decodedData[4], '6'); ck_assert_int_eq(decodedData[5], '2'); ck_assert_int_eq(decodedData[6], '5'); ck_assert_int_eq(decodedData[7], '4'); ck_assert_int_eq(decodedData[8], '1'); ck_assert_int_eq(decodedData[9], '!'); ck_assert_int_eq(decodedData[10], '!'); free(decodedData); }
END_TEST START_TEST(test_mg_get_cookie) { char buf[32]; int ret; const char *longcookie = "key1=1; key2=2; key3; key4=4; key5=; key6; " "key7=this+is+it; key8=8; key9"; /* invalid result buffer */ ret = mg_get_cookie("", "notfound", NULL, 999); ck_assert_int_eq(ret, -2); /* zero size result buffer */ ret = mg_get_cookie("", "notfound", buf, 0); ck_assert_int_eq(ret, -2); /* too small result buffer */ ret = mg_get_cookie("key=toooooooooolong", "key", buf, 4); ck_assert_int_eq(ret, -3); /* key not found in string */ ret = mg_get_cookie("", "notfound", buf, sizeof(buf)); ck_assert_int_eq(ret, -1); ret = mg_get_cookie(longcookie, "notfound", buf, sizeof(buf)); ck_assert_int_eq(ret, -1); /* key not found in string */ ret = mg_get_cookie("key1=1; key2=2; key3=3", "notfound", buf, sizeof(buf)); ck_assert_int_eq(ret, -1); /* keys are found as first, middle and last key */ memset(buf, 77, sizeof(buf)); ret = mg_get_cookie("key1=1; key2=2; key3=3", "key1", buf, sizeof(buf)); ck_assert_int_eq(ret, 1); ck_assert_str_eq("1", buf); memset(buf, 77, sizeof(buf)); ret = mg_get_cookie("key1=1; key2=2; key3=3", "key2", buf, sizeof(buf)); ck_assert_int_eq(ret, 1); ck_assert_str_eq("2", buf); memset(buf, 77, sizeof(buf)); ret = mg_get_cookie("key1=1; key2=2; key3=3", "key3", buf, sizeof(buf)); ck_assert_int_eq(ret, 1); ck_assert_str_eq("3", buf); /* longer value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_cookie(longcookie, "key7", buf, sizeof(buf)); ck_assert_int_eq(ret, 10); ck_assert_str_eq("this+is+it", buf); /* key with = but without value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_cookie(longcookie, "key5", buf, sizeof(buf)); ck_assert_int_eq(ret, 0); ck_assert_str_eq("", buf); /* key without = and without value in the middle of a longer string */ memset(buf, 77, sizeof(buf)); ret = mg_get_cookie(longcookie, "key6", buf, sizeof(buf)); ck_assert_int_eq(ret, -1); /* TODO: mg_get_cookie and mg_get_var(2) should have the same behavior */ }
}END_TEST START_TEST (test_init_search_data4) { init_symbol_translation( TRANS_QUERY, BOTH_STRANDS, 3, 3 ); p_query query = query_read_from_string( "ATGCCCAAGCTGAATAGCGTAGAGGGGTTTTCATCATTTGAGGACGATGTATAA" ); p_search_data sdp = s_create_searchdata( query ); // query data ck_assert_int_eq( 6, sdp->q_count ); seq_buffer_t buf = sdp->queries[0]; ck_assert_str_eq( &query->aa[0].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[0].len, buf.seq.len ); ck_assert_int_eq( 0, buf.frame ); ck_assert_int_eq( 0, buf.strand ); buf = sdp->queries[1]; ck_assert_str_eq( &query->aa[1].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[1].len, buf.seq.len ); ck_assert_int_eq( 1, buf.frame ); ck_assert_int_eq( 0, buf.strand ); buf = sdp->queries[2]; ck_assert_str_eq( &query->aa[2].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[2].len, buf.seq.len ); ck_assert_int_eq( 2, buf.frame ); ck_assert_int_eq( 0, buf.strand ); buf = sdp->queries[3]; ck_assert_str_eq( &query->aa[3].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[3].len, buf.seq.len ); ck_assert_int_eq( 0, buf.frame ); ck_assert_int_eq( 1, buf.strand ); buf = sdp->queries[4]; ck_assert_str_eq( &query->aa[4].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[4].len, buf.seq.len ); ck_assert_int_eq( 1, buf.frame ); ck_assert_int_eq( 1, buf.strand ); buf = sdp->queries[5]; ck_assert_str_eq( &query->aa[5].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[5].len, buf.seq.len ); ck_assert_int_eq( 2, buf.frame ); ck_assert_int_eq( 1, buf.strand ); ck_assert_int_eq( 18, sdp->maxqlen ); query_free( query ); }END_TEST
END_TEST START_TEST(test_basic_remove1) { GpuArray a; GpuArray b; GpuArray c; GpuElemwise *ge; static const uint32_t data1[6] = {1, 2, 3, 4, 5, 6}; static const uint32_t data2[6] = {7, 8, 9, 10, 11, 12}; uint32_t data3[6] = {0}; size_t dims[4]; gpuelemwise_arg args[3] = {{0}}; void *rargs[3]; dims[0] = 1; dims[1] = 3; dims[2] = 2; dims[3] = 1; ga_assert_ok(GpuArray_empty(&a, ctx, GA_UINT, 4, dims, GA_C_ORDER)); ga_assert_ok(GpuArray_write(&a, data1, sizeof(data1))); ga_assert_ok(GpuArray_empty(&b, ctx, GA_UINT, 4, dims, GA_F_ORDER)); ga_assert_ok(GpuArray_write(&b, data2, sizeof(data2))); ga_assert_ok(GpuArray_empty(&c, ctx, GA_UINT, 4, dims, GA_C_ORDER)); args[0].name = "a"; args[0].typecode = GA_UINT; args[0].flags = GE_READ; args[1].name = "b"; args[1].typecode = GA_UINT; args[1].flags = GE_READ; args[2].name = "c"; args[2].typecode = GA_UINT; args[2].flags = GE_WRITE; ge = GpuElemwise_new(ctx, "", "c = a + b", 3, args, 0, 0); ck_assert_ptr_ne(ge, NULL); rargs[0] = &a; rargs[1] = &b; rargs[2] = &c; ga_assert_ok(GpuElemwise_call(ge, rargs, 0)); ga_assert_ok(GpuArray_read(data3, sizeof(data3), &c)); ck_assert_int_eq(data3[0], 8); ck_assert_int_eq(data3[1], 12); ck_assert_int_eq(data3[2], 11); ck_assert_int_eq(data3[3], 15); ck_assert_int_eq(data3[4], 14); ck_assert_int_eq(data3[5], 18); }
void testInitLib(void) { ck_assert_int_eq(qeo_security_init(), QEO_OK); }
END_TEST START_TEST(test_basic_neg_strides) { GpuArray a; GpuArray b; GpuArray c; GpuElemwise *ge; static const uint32_t data1[6] = {1, 2, 3, 4, 5, 6}; static const uint32_t data2[6] = {7, 8, 9, 10, 11, 12}; uint32_t data3[6] = {0}; size_t dims[1]; gpuelemwise_arg args[3] = {{0}}; void *rargs[3]; ssize_t starts[1]; ssize_t stops[1]; ssize_t steps[1]; dims[0] = 6; ga_assert_ok(GpuArray_empty(&a, ctx, GA_UINT, 1, dims, GA_C_ORDER)); ga_assert_ok(GpuArray_write(&a, data1, sizeof(data1))); ga_assert_ok(GpuArray_empty(&b, ctx, GA_UINT, 1, dims, GA_C_ORDER)); ga_assert_ok(GpuArray_write(&b, data2, sizeof(data2))); starts[0] = 5; stops[0] = -1; steps[0] = -1; ga_assert_ok(GpuArray_index_inplace(&b, starts, stops, steps)); ga_assert_ok(GpuArray_empty(&c, ctx, GA_UINT, 1, dims, GA_C_ORDER)); args[0].name = "a"; args[0].typecode = GA_UINT; args[0].flags = GE_READ; args[1].name = "b"; args[1].typecode = GA_UINT; args[1].flags = GE_READ; args[2].name = "c"; args[2].typecode = GA_UINT; args[2].flags = GE_WRITE; ge = GpuElemwise_new(ctx, "", "c = a + b", 3, args, 1, 0); ck_assert_ptr_ne(ge, NULL); rargs[0] = &a; rargs[1] = &b; rargs[2] = &c; ga_assert_ok(GpuElemwise_call(ge, rargs, 0)); ga_assert_ok(GpuArray_read(data3, sizeof(data3), &c)); ck_assert_int_eq(data3[0], 13); ck_assert_int_eq(data3[1], 13); ck_assert_int_eq(data3[2], 13); ck_assert_int_eq(data3[3], 13); ck_assert_int_eq(data3[4], 13); ck_assert_int_eq(data3[5], 13); }
END_TEST /* Разный период */ START_TEST (nes_clock_basic3) { ck_assert_int_eq((NesClock_Test<25, 10, 15, 10, 5>()), 4); }
static bool servicing(void *data, stream_t *stream) { test_service_t *test = (test_service_t*)data; char buf[1024], hdr[256], *start, *end = NULL, *body = NULL, *type = NULL; struct tm tm; time_t t; ssize_t len, tot = 0; int nr = 0; start = buf; /* parse method and headers */ while (end != start) { len = stream->read(stream, buf + tot, sizeof(buf) - tot, TRUE); ck_assert(len > 0); tot += len; while (TRUE) { end = memchr(start, '\n', tot); if (!end) { break; } *end = '\0'; ck_assert(end > buf); ck_assert(*(--end) == '\r'); *end = '\0'; if (end == start) { body = end + strlen("\r\n"); break; } switch (nr++) { case 0: snprintf(hdr, sizeof(hdr), "%s %s HTTP/1.%u", test->meth, test->path, test->minor); ck_assert_str_eq(hdr, start); break; default: if (strcasepfx(start, "Content-Length: ")) { ck_assert_int_eq( atoi(start + strlen("Content-Length: ")), test->req_len); } if (strcasepfx(start, "Content-Type: ")) { type = start + strlen("Content-Type: "); } break; } start = end + strlen("\r\n"); } } if (test->type) { ck_assert(type); ck_assert_str_eq(type, test->type); } /* request body */ if (test->req_len) { ck_assert(stream->read_all(stream, buf + tot, test->req_len - (tot - (body - buf)))); ck_assert(memeq(body, test->req, test->req_len)); } if (!test->code) { test->code = 200; } /* response headers */ snprintf(buf, sizeof(buf), "HTTP/1.%u %u OK\r\n", test->minor, test->code); ck_assert(stream->write_all(stream, buf, strlen(buf))); /* if the response code indicates an error the following write operations * might fail because the client already terminated the TCP connection */ #define may_fail(test, op) ck_assert(op || !HTTP_SUCCESS(test->code)) t = time(NULL); gmtime_r(&t, &tm); strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z", &tm); may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Server: strongSwan unit test\r\n"); may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* rest of response headers */ snprintf(buf, sizeof(buf), "Content-Type: text/plain\r\n"); may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Content-Length: %u\r\n", test->res_len); may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Connection: close\r\n"); may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "\r\n"); may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* response body */ may_fail(test, stream->write_all(stream, test->res, test->res_len)); return FALSE; }
END_TEST /* Выход сразу после vpnes::CClock::Terminated */ START_TEST (nes_clock_basic4) { ck_assert_int_eq((NesClock_Test<0, 10, 15, 10, 10>()), 0); }
END_TEST START_TEST(test_message_encode) { message * msg; char * res; uint32_t len; msg = message_create_echo(MESSAGE_TYPE_REQUEST, "hey"); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 7); ck_assert_int_eq(memcmp(res, "\x93\x00\x01\xa3hey", len), 0); msg = message_decode("\x93\x00\x01\xa3hey", 7); ck_assert(msg != NULL); ck_assert_str_eq(msg->data.echo, "hey"); msg = message_create_echo(MESSAGE_TYPE_RESPONSE, "hey"); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 7); ck_assert_int_eq(memcmp(res, "\x93\x01\x01\xa3hey", len), 0); msg = message_decode("\x93\x01\x01\xa3hey", 7); ck_assert(msg != NULL); ck_assert_str_eq(msg->data.echo, "hey"); msg = message_create_identity(MESSAGE_TYPE_REQUEST, NULL, 0); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 4); ck_assert_int_eq(memcmp(res, "\x93\x00\x00\xc0", len), 0); msg = message_create_identity(MESSAGE_TYPE_RESPONSE, "localhost", 10000); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 17); ck_assert_int_eq(memcmp(res, "\x93\x01\x00\x92\xa9localhost\xcd'\x10", len), 0); msg = message_decode("\x93\x01\x00\x92\xa9localhost\xcd'\x10", 17); ck_assert(msg != NULL); /* ck_assert_int_eq(msg->data.identity.port , 10000); */ /* ck_assert_str_eq(msg->data.identity.name, "localhost"); */ msg = message_create(MESSAGE_TYPE_REQUEST, MESSAGE_ACTION_DISCOVER); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 4); ck_assert_int_eq(memcmp(res, "\x93\x00\x02\xc0", len), 0); msg = message_decode("\x93\x00\x02\xc0", 4); ck_assert(msg != NULL); ck_assert_int_eq(msg->type, MESSAGE_TYPE_REQUEST); ck_assert_int_eq(msg->action, MESSAGE_ACTION_DISCOVER); }
END_TEST /* Вызов vpnes::CClock::Reset не влияет на работу */ START_TEST (nes_clock_basic5) { ck_assert_int_eq((NesClock_Test<30, 10, 15, 10, 10, 1>()), 3); }
END_TEST START_TEST(test_mg_start_stop_https_server) { #ifndef NO_SSL struct mg_context *ctx; size_t ports_cnt; int ports[16]; int ssl[16]; struct mg_callbacks callbacks; char errmsg[256]; const char *OPTIONS[8]; /* initializer list here is rejected by CI test */ int opt_idx = 0; const char *ssl_cert = locate_ssl_cert(); struct mg_connection *client_conn; char client_err[256]; const struct mg_request_info *client_ri; int client_res; ck_assert(ssl_cert != NULL); memset((void *)OPTIONS, 0, sizeof(OPTIONS)); #if !defined(NO_FILES) OPTIONS[opt_idx++] = "document_root"; OPTIONS[opt_idx++] = "."; #endif OPTIONS[opt_idx++] = "listening_ports"; OPTIONS[opt_idx++] = "8080r,8443s"; OPTIONS[opt_idx++] = "ssl_certificate"; OPTIONS[opt_idx++] = ssl_cert; ck_assert_int_le(opt_idx, (int)(sizeof(OPTIONS) / sizeof(OPTIONS[0]))); ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 1] == NULL); ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 2] == NULL); memset(ports, 0, sizeof(ports)); memset(ssl, 0, sizeof(ssl)); memset(&callbacks, 0, sizeof(callbacks)); memset(errmsg, 0, sizeof(errmsg)); callbacks.log_message = log_msg_func; ctx = mg_start(&callbacks, (void *)errmsg, OPTIONS); test_sleep(1); ck_assert_str_eq(errmsg, ""); ck_assert(ctx != NULL); ports_cnt = mg_get_ports(ctx, 16, ports, ssl); ck_assert_uint_eq(ports_cnt, 2); ck_assert_int_eq(ports[0], 8080); ck_assert_int_eq(ssl[0], 0); ck_assert_int_eq(ports[1], 8443); ck_assert_int_eq(ssl[1], 1); ck_assert_int_eq(ports[2], 0); ck_assert_int_eq(ssl[2], 0); test_sleep(1); memset(client_err, 0, sizeof(client_err)); client_conn = mg_connect_client("127.0.0.1", 8443, 1, client_err, sizeof(client_err)); ck_assert(client_conn != NULL); ck_assert_str_eq(client_err, ""); mg_printf(client_conn, "GET / HTTP/1.0\r\n\r\n"); client_res = mg_get_response(client_conn, client_err, sizeof(client_err), 10000); ck_assert_int_ge(client_res, 0); ck_assert_str_eq(client_err, ""); client_ri = mg_get_request_info(client_conn); ck_assert(client_ri != NULL); #if defined(NO_FILES) ck_assert_str_eq(client_ri->uri, "404"); #else ck_assert_str_eq(client_ri->uri, "200"); /* TODO: ck_assert_str_eq(client_ri->request_method, "HTTP/1.0"); */ client_res = (int)mg_read(client_conn, client_err, sizeof(client_err)); ck_assert_int_gt(client_res, 0); ck_assert_int_le(client_res, sizeof(client_err)); #endif mg_close_connection(client_conn); test_sleep(1); mg_stop(ctx); #endif }
END_TEST /* Преждевременное завершение */ START_TEST (nes_clock_basic2) { ck_assert_int_eq((NesClock_Test<20, 10, 15, 10, 10>()), 2); }
END_TEST START_TEST (test_riemann_simple_communicate) { riemann_client_t *client, *dummy_client; riemann_message_t *message, *response; client = riemann_client_create (RIEMANN_CLIENT_TCP, "127.0.0.1", 5555); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); ck_assert (riemann_communicate (NULL, NULL) == NULL); ck_assert_errno (-errno, ENOTCONN); ck_assert (riemann_communicate (client, NULL) == NULL); ck_assert_errno (-errno, EINVAL); ck_assert (riemann_communicate (NULL, message) == NULL); ck_assert_errno (-errno, ENOTCONN); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); dummy_client = riemann_client_new (); ck_assert (riemann_communicate (dummy_client, message) == NULL); ck_assert_errno (-errno, ENOTCONN); riemann_client_free (dummy_client); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); response = riemann_communicate (client, message); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); riemann_message_free (response); response = riemann_communicate (client, riemann_message_create_with_query (riemann_query_new ("true"))); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); ck_assert (response->n_events > 0); riemann_message_free (response); riemann_client_disconnect (client); riemann_client_connect (client, RIEMANN_CLIENT_UDP, "127.0.0.1", 5555); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); response = riemann_communicate (client, message); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); riemann_message_free (response); riemann_client_disconnect (client); riemann_client_connect (client, RIEMANN_CLIENT_TCP, "127.0.0.1", 5555); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate #2", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); riemann_message_set_query (message, riemann_query_new ("true")); response = riemann_communicate (client, message); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); ck_assert (response->n_events > 0); riemann_message_free (response); riemann_client_disconnect (client); riemann_client_connect (client, RIEMANN_CLIENT_UDP, "127.0.0.1", 5555); message = riemann_message_create_with_events (riemann_event_create (RIEMANN_EVENT_FIELD_HOST, "localhost", RIEMANN_EVENT_FIELD_SERVICE, "test_riemann_simple_communicate #2", RIEMANN_EVENT_FIELD_STATE, "ok", RIEMANN_EVENT_FIELD_NONE), NULL); riemann_message_set_query (message, riemann_query_new ("true")); response = riemann_communicate (client, message); ck_assert (response != NULL); ck_assert_int_eq (response->ok, 1); ck_assert (response->n_events == 0); riemann_message_free (response); riemann_client_disconnect (client); riemann_client_free (client); }
static void checkAllReleased(void *context, const UA_Node* node) { UA_NodeMapEntry *entry = container_of(node, UA_NodeMapEntry, node); ck_assert_int_eq(entry->refCount, 1); /* The count is increased when the visited node is checked out */ }