소스 검색

Truncate strings in the test, so string compare functions can be used in the test (test framework does not support memcompare functions)

bel 8 년 전
부모
커밋
7f7eaad07e
1개의 변경된 파일13개의 추가작업 그리고 1개의 파일을 삭제
  1. 13 1
      test/public_server.c

+ 13 - 1
test/public_server.c

@@ -1729,8 +1729,18 @@ field_found(const char *key,
 static int g_field_step;
 
 static int
-field_get(const char *key, const char *value, size_t valuelen, void *user_data)
+field_get(const char *key,
+          const char *value_untruncated,
+          size_t valuelen,
+          void *user_data)
 {
+	/* Copy the untruncated value, so string compare functions can be used. */
+	/* The check unit test library does not have build in memcmp functions. */
+	char *value = (char *)malloc(valuelen + 1);
+	ck_assert(value != NULL);
+	memcpy(value, value_untruncated, valuelen);
+	value[valuelen] = 0;
+
 	ck_assert_ptr_eq(user_data, (void *)&g_field_found_return);
 	ck_assert_int_ge(g_field_step, 0);
 
@@ -1851,6 +1861,8 @@ field_get(const char *key, const char *value, size_t valuelen, void *user_data)
 		             (int)g_field_step);
 	}
 
+	free(value);
+
 	return 0;
 }