page_tests.c (1358B)
1 #include "writer/gopher/page.h" 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include "fs_inmemory.h" 8 #include "git/repo.h" 9 #include "test_utils.h" 10 #include "utest.h" 11 12 struct gopher_page { 13 int dummy; 14 }; 15 16 UTEST_F_SETUP(gopher_page) { 17 inmemory_fs_clear(); 18 } 19 20 UTEST_F_TEARDOWN(gopher_page) {} 21 22 UTEST_F(gopher_page, basic) { 23 RepoSpecialFile sf = {.label = "LICENSE", .path = "LICENSE"}; 24 GitRepo repo = { 25 .short_name = "test-repo", 26 .description = "Repo description", 27 .clone_url = "git://example.com/repo.git", 28 .special_files = &sf, 29 .special_files_len = 1, 30 }; 31 32 FILE* out = g_fs_inmemory->fopen("test.gph", "w"); 33 GopherPage* page = 34 gopher_page_create(out, &repo, g_fs_inmemory, "Page Title", "rel"); 35 ASSERT_NE(NULL, page); 36 37 gopher_page_begin(page); 38 gopher_page_end(page); 39 g_fs_inmemory->fclose(out); 40 gopher_page_free(page); 41 42 const char* buf = inmemory_fs_get_buffer("test.gph"); 43 ASSERT_NE(NULL, buf); 44 45 /* Verify Header/Title */ 46 EXPECT_STR_SEQUENCE(buf, "Page Title", "test-repo", "Repo description"); 47 48 /* Verify Navigation */ 49 EXPECT_STR_SEQUENCE(buf, "[1|Log|", "log.gph", "[1|Files|", "files.gph", 50 "[1|Refs|", "refs.gph"); 51 52 /* Verify Metadata */ 53 EXPECT_STR_SEQUENCE(buf, "git clone", "git://example.com/repo.git", 54 "LICENSE"); 55 }