Browse Source

testcase for array_list

tags/json-c-0.14-20200419
chenguoping dota17 5 years ago
parent
commit
76e1472808
7 changed files with 130 additions and 0 deletions
  1. +46
    -0
      tests/test1.c
  2. +14
    -0
      tests/test1.expected
  3. +14
    -0
      tests/test1Formatted_plain.expected
  4. +14
    -0
      tests/test1Formatted_pretty.expected
  5. +14
    -0
      tests/test1Formatted_spaced.expected
  6. +14
    -0
      tests/test1Formatted_spaced_pretty.expected
  7. +14
    -0
      tests/test1Formatted_spaced_pretty_pretty_tab.expected

+ 46
- 0
tests/test1.c View File

@@ -136,6 +136,48 @@ void test_array_del_idx()
json_object_put(my_array);
}

void test_array_list_expand_internal(void);
void test_array_list_expand_internal()
{
int rc;
size_t ii;
size_t idx;
json_object *my_array;
#ifdef TEST_FORMATTED
int sflags = 0;
#endif

my_array = make_array();
printf("my_array=\n");
for(ii = 0; ii < json_object_array_length(my_array); ii++)
{
json_object *obj = json_object_array_get_idx(my_array, ii);
printf("\t[%d]=%s\n", (int)ii, json_object_to_json_string(obj));
}
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
/* Put iNdex < array->size, no expand. */
rc = json_object_array_put_idx(my_array, 5, json_object_new_int(6));
printf("put_idx(5,6)=%d\n", rc);
/* array->size < Put Index < array->size * 2 <= SIZE_T_MAX, the size = array->size * 2. */
idx = ARRAY_LIST_DEFAULT_SIZE * 2 - 1;
rc = json_object_array_put_idx(my_array, idx, json_object_new_int(0));
printf("put_idx(%d,0)=%d\n", (int)(idx), rc);
/* array->size * 2 < Put Index, the size = Put Index. */
idx = ARRAY_LIST_DEFAULT_SIZE * 2 * 2 + 1;
rc = json_object_array_put_idx(my_array, idx, json_object_new_int(0));
printf("put_idx(%d,0)=%d\n", (int)(idx), rc);
/* SIZE_T_MAX <= Put Index, it will fail and the size will no change. */
idx = SIZE_MAX; // SIZE_MAX = SIZE_T_MAX
rc = json_object_array_put_idx(my_array, idx, json_object_new_int(0));
printf("put_idx(SIZE_T_MAX,0)=%d\n", rc);
json_object_put(my_array);
}

int main(int argc, char **argv)
{
json_object *my_string, *my_int, *my_null, *my_object, *my_array;
@@ -201,6 +243,7 @@ int main(int argc, char **argv)
json_object_put(my_array);

test_array_del_idx();
test_array_list_expand_internal();

my_array = json_object_new_array();
json_object_array_add(my_array, json_object_new_int(3));
@@ -222,6 +265,9 @@ int main(int argc, char **argv)
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
}
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
json_object* result = json_object_array_bsearch(json_object_new_int(1), my_array, sort_fn);
printf("find json_object(1) in my_array successfully: %s\n", json_object_to_json_string(result));

my_object = json_object_new_object();
int rc = json_object_object_add(my_object, "abc", my_object);


+ 14
- 0
tests/test1.expected View File

@@ -41,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[ ]
after del_idx(0,8)=-1, my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ]
after del_idx(0,6)=0, my_array.to_string()=[ 7 ]
after adding more entries, my_array.to_string()=[ 7, "s1", "s2", "s3" ]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -55,6 +68,7 @@ my_array=
[3]=2
[4]=3
my_array.to_string()=[ null, 0, 1, 2, 3 ]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


+ 14
- 0
tests/test1Formatted_plain.expected View File

@@ -41,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[]
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
after del_idx(0,6)=0, my_array.to_string()=[7]
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[1,2,3,4,5,null,7]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -55,6 +68,7 @@ my_array=
[3]=2
[4]=3
my_array.to_string()=[null,0,1,2,3]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


+ 14
- 0
tests/test1Formatted_pretty.expected View File

@@ -47,6 +47,19 @@ after del_idx(0,7)=0, my_array.to_string()=[]
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
after del_idx(0,6)=0, my_array.to_string()=[7]
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[1,2,3,4,5,null,7]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -73,6 +86,7 @@ my_array.to_string()=[
2,
3
]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


+ 14
- 0
tests/test1Formatted_spaced.expected View File

@@ -41,6 +41,19 @@ after del_idx(0,7)=0, my_array.to_string()=[]
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
after del_idx(0,6)=0, my_array.to_string()=[7]
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[1,2,3,4,5,null,7]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -55,6 +68,7 @@ my_array=
[3]=2
[4]=3
my_array.to_string()=[ null, 0, 1, 2, 3 ]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


+ 14
- 0
tests/test1Formatted_spaced_pretty.expected View File

@@ -47,6 +47,19 @@ after del_idx(0,7)=0, my_array.to_string()=[]
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
after del_idx(0,6)=0, my_array.to_string()=[7]
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[1,2,3,4,5,null,7]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -73,6 +86,7 @@ my_array.to_string()=[
2,
3
]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


+ 14
- 0
tests/test1Formatted_spaced_pretty_pretty_tab.expected View File

@@ -47,6 +47,19 @@ after del_idx(0,7)=0, my_array.to_string()=[]
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
after del_idx(0,6)=0, my_array.to_string()=[7]
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
my_array=
[0]=1
[1]=2
[2]=3
[3]=4
[4]=5
[5]=null
[6]=7
my_array.to_string()=[1,2,3,4,5,null,7]
put_idx(5,6)=0
put_idx(63,0)=0
put_idx(129,0)=0
put_idx(SIZE_T_MAX,0)=-1
my_array=
[0]=3
[1]=1
@@ -73,6 +86,7 @@ my_array.to_string()=[
2,
3
]
find json_object(1) in my_array successfully: 1
baz_obj.to_string()="fark"
my_object=
abc: 12


Loading…
Cancel
Save