gout_tests.c (1492B)
1 #include "gout.h" 2 3 #include "utest.h" 4 5 UTEST(gout_options_create, ReturnsNullIfNoRepoSpecified) { 6 int argc = 1; 7 const char* argv[1] = {"path/to/gout"}; 8 GoutOptions* options = gout_options_create(argc, argv); 9 EXPECT_EQ(NULL, options); 10 } 11 12 UTEST(gout_options_create, ReturnsInitializedOptions) { 13 int argc = 2; 14 const char* argv[2] = {"path/to/gout", "some/path/myrepo"}; 15 GoutOptions* options = gout_options_create(argc, argv); 16 ASSERT_NE(NULL, options); 17 gout_options_free(options); 18 } 19 20 #include "fs_inmemory.h" 21 22 UTEST(fs_inmemory, overwrite_file) { 23 inmemory_fs_clear(); 24 25 // 1. Write initial content. 26 FILE* f1 = g_fs_inmemory->fopen("test_file.txt", "w"); 27 ASSERT_NE(NULL, f1); 28 fprintf(f1, "Initial Content"); 29 g_fs_inmemory->fclose(f1); 30 31 // Verify we can read it. 32 FILE* r1 = g_fs_inmemory->fopen("test_file.txt", "r"); 33 ASSERT_NE(NULL, r1); 34 char buf[64]; 35 memset(buf, 0, sizeof(buf)); 36 fgets(buf, sizeof(buf), r1); 37 EXPECT_STREQ("Initial Content", buf); 38 g_fs_inmemory->fclose(r1); 39 40 // 2. Overwrite the file. 41 FILE* f2 = g_fs_inmemory->fopen("test_file.txt", "w"); 42 ASSERT_NE(NULL, f2); 43 fprintf(f2, "New Updated Content"); 44 g_fs_inmemory->fclose(f2); 45 46 // Verify that the read returns the NEW updated content. 47 FILE* r2 = g_fs_inmemory->fopen("test_file.txt", "r"); 48 ASSERT_NE(NULL, r2); 49 memset(buf, 0, sizeof(buf)); 50 fgets(buf, sizeof(buf), r2); 51 EXPECT_STREQ("New Updated Content", buf); 52 g_fs_inmemory->fclose(r2); 53 54 inmemory_fs_clear(); 55 }