-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add some test #967
Conversation
npes87184
commented
Nov 30, 2019
- 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>
👍 Cool, more tests! 🎉 I will review this soon. |
There was a problem hiding this 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))); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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);
}
LGTM! |