Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some test #967

Closed
wants to merge 3 commits into from
Closed

Add some test #967

wants to merge 3 commits into from

Conversation

npes87184
Copy link
Contributor

  • test_strquote
  • test_buffer_util

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
@rom1v
Copy link
Collaborator

rom1v commented Dec 1, 2019

👍 Cool, more tests! 🎉

I will review this soon.

Copy link
Collaborator

@rom1v rom1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. 👍

If you're ok with my proposed diff, I can merge them directly 😉

assert((strlen(s) + 2) == strlen(out));

// check only add '"' in the begin and the end
assert(!strncmp(s, out + 1, strlen(s)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to replace this by a single strcmp() call:

diff --git a/app/tests/test_strutil.c b/app/tests/test_strutil.c
index f4afabd..1489b1b 100644
--- a/app/tests/test_strutil.c
+++ b/app/tests/test_strutil.c
@@ -131,11 +131,8 @@ static void test_strquote(void) {
     const char *s = "abcde";
     char *out = strquote(s);
 
-    // add '"' in the begin and the end, also check out is null terminated
-    assert((strlen(s) + 2) == strlen(out));
-
-    // check only add '"' in the begin and the end
-    assert(!strncmp(s, out + 1, strlen(s)));
+    // add '"' at the beginning and the end
+    assert(!strcmp("\"abcde\"", out));
 
     SDL_free(out);
 }

It catches more possible errors (it asserts the expected output, not only some of its characteristics).

static inline
uint64_t buffer_read64be(const uint8_t *buf) {
static inline uint64_t
buffer_read64be(const uint8_t *buf) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

val = buffer_read64be(buf);

assert(val == 0xABCD1234567890EF);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(nitpick: I would just change the code style a bit)

diff --git a/app/tests/test_buffer_util.c b/app/tests/test_buffer_util.c
index 3d2cf3b..ba3f9f0 100644
--- a/app/tests/test_buffer_util.c
+++ b/app/tests/test_buffer_util.c
@@ -41,29 +41,26 @@ static void test_buffer_write64be(void) {
 }
 
 static void test_buffer_read16be(void) {
-    uint16_t val;
     uint8_t buf[2] = {0xAB, 0xCD};
 
-    val = buffer_read16be(buf);
+    uint16_t val = buffer_read16be(buf);
 
     assert(val == 0xABCD);
 }
 
 static void test_buffer_read32be(void) {
-    uint32_t val;
     uint8_t buf[4] = {0xAB, 0xCD, 0x12, 0x34};
 
-    val = buffer_read32be(buf);
+    uint32_t val = buffer_read32be(buf);
 
     assert(val == 0xABCD1234);
 }
 
 static void test_buffer_read64be(void) {
-    uint64_t val;
     uint8_t buf[8] = {0xAB, 0xCD, 0x12, 0x34,
                       0x56, 0x78, 0x90, 0xEF};
 
-    val = buffer_read64be(buf);
+    uint64_t val = buffer_read64be(buf);
 
     assert(val == 0xABCD1234567890EF);
 }

@npes87184
Copy link
Contributor Author

LGTM!

rom1v added a commit that referenced this pull request Dec 4, 2019
@rom1v
Copy link
Collaborator

rom1v commented Dec 4, 2019

Merged on dev:

@rom1v rom1v closed this Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants