Skip to content

Commit

Permalink
fix test to include \0 terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
Beej Jorgensen committed Dec 7, 2018
1 parent feab212 commit 7c5ac16
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/cache_tests/cache_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ char *test_cache_alloc_entry()
char *path = "/bazz/lurman.html";
char *content_type = "text/html";
char *content = "<head>Bazz Lurman</head>";
int content_len = strlen(content) + 1; // +1 to include the \0

struct cache_entry *ce = alloc_entry(path, content_type, content, strlen(content));
struct cache_entry *ce = alloc_entry(path, content_type, content, content_len);

// Check that the allocated entry was initialized with expected values
mu_assert(check_strings(ce->path, path) == 0, "Your alloc_entry function did not allocate the path field to the expected string");
mu_assert(check_strings(ce->content_type, content_type) == 0, "Your alloc_entry function did not allocate the content_type field to the expected string");
mu_assert(check_strings(ce->content, content) == 0, "Your alloc_entry function did not allocate the content field to the expected string");
mu_assert(ce->content_length == strlen(content), "Your alloc_entry function did not allocate the content_length field to the expected length");
mu_assert(ce->content_length == content_len, "Your alloc_entry function did not allocate the content_length field to the expected length")

free_entry(ce);

Expand All @@ -60,7 +61,7 @@ char *test_cache_put()
mu_assert(cache->cur_size == 1, "Your cache_put function did not correctly increment the cur_size field when adding a new cache entry");
mu_assert(cache->head->prev == NULL && cache->tail->next == NULL, "The head and tail of your cache should have NULL prev and next pointers when a new entry is put in an empty cache");
mu_assert(check_cache_entries(cache->head, test_entry_1) == 0, "Your cache_put function did not put an entry into the head of the empty cache with the expected form");
mu_assert(check_cache_entries(cache->tail, test_entry_1) == 0, "Your cache_put function did not put an entry into the tail of the empty cache with the expected form");
mu_assert(check_cache_entries(cache->tail, test_entry_1) == 0, "Your cache_put function did not put an entry into the tail of the empty cache with the expected form")
mu_assert(check_cache_entries(hashtable_get(cache->index, "/1"), test_entry_1) == 0, "Your cache_put function did not put the expected entry into the hashtable");

// Add in a second entry to the cache
Expand Down Expand Up @@ -157,4 +158,4 @@ char *all_tests()
return NULL;
}

RUN_TESTS(all_tests)
RUN_TESTS(all_tests)

0 comments on commit 7c5ac16

Please sign in to comment.