@@ -43,6 +43,10 @@ void *sum_callback(size_t argc, void *args[], void *data)
4343
4444void *test_string_reference (size_t argc, void *args[], void *data)
4545{
46+ (void )argc;
47+ (void )data;
48+
49+ /* Get string from pointer */
4650 printf (" ptr %p\n " , args[0 ]);
4751 fflush (stdout);
4852
@@ -54,13 +58,12 @@ void *test_string_reference(size_t argc, void *args[], void *data)
5458
5559 char *str = metacall_value_to_string (string_value);
5660
57- (void )argc;
58- (void )data;
59-
6061 printf (" native string %s\n " , str);
6162
63+ /* Check it is a valid string */
6264 EXPECT_STREQ (" asd" , str);
6365
66+ /* Replace the string, it will be choped by the previous length */
6467 static const char yeet[] = " yeet" ;
6568
6669 metacall_value_from_string (string_value, yeet, sizeof (yeet) - 1 );
@@ -69,6 +72,13 @@ void *test_string_reference(size_t argc, void *args[], void *data)
6972 printf (" native string %s\n " , str);
7073 fflush (stdout);
7174
75+ EXPECT_STREQ (" yee" , str);
76+
77+ /* Define a new string in the pointer value */
78+ static const char hello[] = " hello world" ;
79+
80+ metacall_value_from_ptr (args[0 ], metacall_value_create_string (hello, sizeof (hello) - 1 ));
81+
7282 return metacall_value_create_null ();
7383}
7484
@@ -325,26 +335,34 @@ TEST_F(metacall_c_test, DefaultConstructor)
325335 printf (" type id %s\n " , metacall_value_type_name (str_value));
326336 fflush (stdout);
327337
328- // It chops the string because it has a fixed size from 'asd'
338+ /* It chops the string because it has a fixed size from 'asd' */
329339 EXPECT_STREQ (metacall_value_to_string (str_value), " yee" );
330340
331341 metacall_value_destroy (str_value);
342+
343+ /* It should contain the new string */
344+ void *new_str = metacall_value_dereference (str_value_ref);
345+
346+ EXPECT_STREQ (metacall_value_to_string (new_str), " hello world" );
347+
348+ metacall_value_destroy (new_str);
332349 metacall_value_destroy (str_value_ref);
333350 }
334351
335- /* References (C) */
352+ /* References (C: string ) */
336353 {
337354 static const char str[] = " asd" ;
338355 void *str_value = metacall_value_create_string (str, sizeof (str) - 1 );
339356 void *str_value_ref = metacall_value_reference (str_value);
357+ void *str_value_ref_ref = metacall_value_reference (str_value_ref);
340358
341359 printf (" (R) ptr %p\n " , str_value_ref);
342360 printf (" (R) string ptr %p\n " , str_value);
343361 printf (" (R) string str %s\n " , metacall_value_to_string (str_value));
344362 fflush (stdout);
345363
346364 void *args[] = {
347- str_value_ref
365+ str_value_ref_ref
348366 };
349367
350368 ret = metacallv_s (" modify_str_ptr" , args, 1 );
@@ -361,6 +379,35 @@ TEST_F(metacall_c_test, DefaultConstructor)
361379
362380 metacall_value_destroy (str_value);
363381 metacall_value_destroy (str_value_ref);
382+ metacall_value_destroy (str_value_ref_ref);
383+ }
384+
385+ /* References (C: int) */
386+ {
387+ void *int_value = metacall_value_create_long (324444L );
388+ void *int_value_ref = metacall_value_reference (int_value);
389+
390+ printf (" (R) ptr %p\n " , int_value_ref);
391+ printf (" (R) int ptr %p\n " , int_value);
392+ printf (" (R) int value %ld\n " , metacall_value_to_long (int_value));
393+ fflush (stdout);
394+
395+ void *args[] = {
396+ int_value_ref
397+ };
398+
399+ ret = metacallv_s (" modify_int_ptr" , args, 1 );
400+
401+ EXPECT_NE ((void *)NULL , (void *)ret);
402+
403+ EXPECT_EQ ((enum metacall_value_id)metacall_value_id (ret), (enum metacall_value_id)METACALL_NULL);
404+
405+ metacall_value_destroy (ret);
406+
407+ EXPECT_EQ ((long )metacall_value_to_long (int_value), (long )111L );
408+
409+ metacall_value_destroy (int_value);
410+ metacall_value_destroy (int_value_ref);
364411 }
365412
366413 /* Print inspect information */
0 commit comments