static void parse_valid_test(void) { struct iscsi_param *params; int rc; params = NULL; char *data; int len; char *partial_parameter = NULL; /* simple test with a single key=value */ PARSE("Abc=def\0", false, NULL); CU_ASSERT(rc == 0); EXPECT_VAL("Abc", "def"); /* multiple key=value pairs */ PARSE("Aaa=bbbbbb\0Xyz=test\0", false, NULL); CU_ASSERT(rc == 0); EXPECT_VAL("Aaa", "bbbbbb"); EXPECT_VAL("Xyz", "test"); /* value with embedded '=' */ PARSE("A=b=c\0", false, NULL); CU_ASSERT(rc == 0); EXPECT_VAL("A", "b=c"); /* CHAP_C=AAAA.... with value length 8192 */ len = strlen("CHAP_C=") + ISCSI_TEXT_MAX_VAL_LEN + 1/* null terminators */; data = malloc(len); SPDK_CU_ASSERT_FATAL(data != NULL); memset(data, 'A', len); strcpy(data, "CHAP_C"); data[6] = '='; data[len - 1] = '\0'; rc = spdk_iscsi_parse_params(¶ms, data, len, false, NULL); CU_ASSERT(rc == 0); free(data); /* partial parameter: value is partial*/ PARSE("C=AAA\0D=B", true, &partial_parameter); SPDK_CU_ASSERT_FATAL(partial_parameter != NULL); CU_ASSERT_STRING_EQUAL(partial_parameter, "D=B"); CU_ASSERT(rc == 0); EXPECT_VAL("C", "AAA"); EXPECT_NULL("D"); PARSE("XXXX\0E=UUUU\0", false, &partial_parameter); CU_ASSERT(rc == 0); EXPECT_VAL("D", "BXXXX"); EXPECT_VAL("E", "UUUU"); CU_ASSERT_PTR_NULL(partial_parameter); /* partial parameter: key is partial*/ PARSE("IAMAFAK", true, &partial_parameter); CU_ASSERT_STRING_EQUAL(partial_parameter, "IAMAFAK"); CU_ASSERT(rc == 0); EXPECT_NULL("IAMAFAK"); PARSE("EDKEY=TTTT\0F=IIII", false, &partial_parameter); CU_ASSERT(rc == 0); EXPECT_VAL("IAMAFAKEDKEY", "TTTT"); EXPECT_VAL("F", "IIII"); CU_ASSERT_PTR_NULL(partial_parameter); /* Second partial parameter is the only parameter */ PARSE("OOOO", true, &partial_parameter); CU_ASSERT_STRING_EQUAL(partial_parameter, "OOOO"); CU_ASSERT(rc == 0); EXPECT_NULL("OOOO"); PARSE("LL=MMMM", false, &partial_parameter); CU_ASSERT(rc == 0); EXPECT_VAL("OOOOLL", "MMMM"); CU_ASSERT_PTR_NULL(partial_parameter); spdk_iscsi_param_free(params); }
static void parse_invalid_test(void) { struct iscsi_param *params; int rc; params = NULL; char *data; int len; /* key without '=' */ PARSE("Abc\0", false, NULL); CU_ASSERT(rc != 0); EXPECT_NULL("Abc"); /* multiple key=value pairs, one missing '=' */ PARSE("Abc=def\0Xyz\0Www=test\0", false, NULL); CU_ASSERT(rc != 0); EXPECT_VAL("Abc", "def"); EXPECT_NULL("Xyz"); EXPECT_NULL("Www"); /* empty key */ PARSE("=abcdef", false, NULL); CU_ASSERT(rc != 0); EXPECT_NULL(""); /* CHAP_C=AAAA.... with value length 8192 + 1 */ len = strlen("CHAP_C=") + ISCSI_TEXT_MAX_VAL_LEN + 1 /* max value len + 1 */ + 1 /* null terminators */; data = malloc(len); SPDK_CU_ASSERT_FATAL(data != NULL); memset(data, 'A', len); strcpy(data, "CHAP_C"); data[6] = '='; data[len - 1] = '\0'; rc = spdk_iscsi_parse_params(¶ms, data, len, false, NULL); free(data); CU_ASSERT(rc != 0); EXPECT_NULL("CHAP_C"); /* Test simple value, length of value bigger than 255*/ len = strlen("A=") + ISCSI_TEXT_MAX_SIMPLE_VAL_LEN + 1 /* max simple value len + 1 */ + 1 /* null terminators */; data = malloc(len); SPDK_CU_ASSERT_FATAL(data != NULL); memset(data, 'A', len); data[1] = '='; data[len - 1] = '\0'; rc = spdk_iscsi_parse_params(¶ms, data, len, false, NULL); free(data); CU_ASSERT(rc != 0); EXPECT_NULL("A"); /* key length bigger than 63 */ len = ISCSI_TEXT_MAX_KEY_LEN + 1 /*max key length + 1*/ + 1 /* = */ + 1 /* A */ + 1/* null terminators */; data = malloc(len); SPDK_CU_ASSERT_FATAL(data != NULL); memset(data, 'A', len); data[64] = '='; data[len - 1] = '\0'; rc = spdk_iscsi_parse_params(¶ms, data, len, false, NULL); free(data); CU_ASSERT(rc != 0); EXPECT_NULL("A"); /* duplicated key */ PARSE("B=BB", false, NULL); CU_ASSERT(rc == 0); PARSE("B=BBBB", false, NULL); CU_ASSERT(rc != 0); EXPECT_VAL("B", "BB"); spdk_iscsi_param_free(params); }
bool VC2Decoder::parseSeqHeader(char *_idata) { #define EXPECT_VAL(N) { uint32_t d = read_uint(idata, bits);\ if (d != (N)) {\ writelog(LOG_WARN, "%s:%d: Expected %d, got %d when parsing sequence header\n", __FILE__, __LINE__, (N), d); \ }\ } uint8_t *idata = (uint8_t *)_idata; if ((!mSeqHeaderEncoded) || mSeqHeaderEncodedLength == 0 || (memcmp(mSeqHeaderEncoded, idata, mSeqHeaderEncodedLength) != 0)) { writelog(LOG_INFO, "Processing Sequence Header"); int bits = 7; EXPECT_VAL(2); EXPECT_VAL(0); EXPECT_VAL(3); int level = read_uint(idata, bits); if (level != 3 && level != 6) { writelog(LOG_WARN, "%s:%d: Expected 3 or 6, got %d when reading level\n", __FILE__, __LINE__, level); } VC2DecoderParamsInternal params; params = mParams; params.video_format.base_video_format = read_uint(idata, bits); params.video_format.custom_dimensions_flag = read_bool(idata, bits); if (params.video_format.custom_dimensions_flag) { params.video_format.frame_width = read_uint(idata, bits); params.video_format.frame_height = read_uint(idata, bits); } params.video_format.custom_color_diff_format_flag = read_bool(idata, bits); if (params.video_format.custom_color_diff_format_flag) { params.video_format.color_diff_format_index = read_uint(idata, bits); } params.video_format.custom_scan_format_flag = read_bool(idata, bits); if (params.video_format.custom_scan_format_flag) { params.video_format.source_sampling = read_uint(idata, bits); } params.video_format.custom_frame_rate_flag = read_bool(idata, bits); if (params.video_format.custom_frame_rate_flag) { params.video_format.frame_rate_index = read_uint(idata, bits); if (params.video_format.frame_rate_index == 0) { params.video_format.frame_rate_numer = read_uint(idata, bits); params.video_format.frame_rate_denom = read_uint(idata, bits); } } params.video_format.custom_pixel_aspect_ratio_flag = read_bool(idata, bits); if (params.video_format.custom_pixel_aspect_ratio_flag) { params.video_format.pixel_aspect_ratio_index = read_uint(idata, bits); if (params.video_format.pixel_aspect_ratio_index == 0) { params.video_format.pixel_aspect_ratio_numer = read_uint(idata, bits); params.video_format.pixel_aspect_ratio_denom = read_uint(idata, bits); } } params.video_format.custom_clean_area_flag = read_bool(idata, bits); if (params.video_format.custom_clean_area_flag) { params.video_format.clean_width = read_uint(idata, bits); params.video_format.clean_height = read_uint(idata, bits); params.video_format.left_offset = read_uint(idata, bits); params.video_format.top_offset = read_uint(idata, bits); } params.video_format.custom_signal_range_flag = read_bool(idata, bits); if (params.video_format.custom_signal_range_flag) { params.video_format.signal_range_index = read_uint(idata, bits); if (params.video_format.signal_range_index == 0) { params.video_format.luma_offset = read_uint(idata, bits); params.video_format.luma_excursion = read_uint(idata, bits); params.video_format.color_diff_offset = read_uint(idata, bits); params.video_format.color_diff_excursion = read_uint(idata, bits); } } params.video_format.custom_color_spec_flag = read_bool(idata, bits); if (params.video_format.custom_color_spec_flag) { params.video_format.color_spec_index = read_uint(idata, bits); if (params.video_format.color_spec_index == 0) { params.video_format.custom_color_primaries_flag = read_bool(idata, bits); if (params.video_format.custom_color_primaries_flag) { params.video_format.color_primaries_index = read_uint(idata, bits); } params.video_format.custom_color_matrix_flag = read_bool(idata, bits); if (params.video_format.custom_color_matrix_flag) { params.video_format.color_matrix_index = read_uint(idata, bits); } params.video_format.custom_transfer_function_flag = read_bool(idata, bits); if (params.video_format.custom_transfer_function_flag) { params.video_format.transfer_function_index = read_uint(idata, bits); } } } uint32_t picture_coding_mode = read_uint(idata, bits); mInterlaced = (picture_coding_mode != 0); mParams = params; mConfigured = false; setVideoFormat(mParams); byte_align(idata, bits); if (mSeqHeaderEncoded) delete[] mSeqHeaderEncoded; mSeqHeaderEncodedLength = idata - (uint8_t *)_idata; mSeqHeaderEncoded = new uint8_t[mSeqHeaderEncodedLength]; memcpy(mSeqHeaderEncoded, _idata, mSeqHeaderEncodedLength); mSequenceInfo.video_format = params.video_format; mSequenceInfo.picture_coding_mode = picture_coding_mode; mSequenceInfo.sequence_headers_seen++; return true; } return false; }