aboutsummaryrefslogtreecommitdiff
path: root/drive-sdk/test/anki_greatest.h
diff options
context:
space:
mode:
Diffstat (limited to 'drive-sdk/test/anki_greatest.h')
-rw-r--r--drive-sdk/test/anki_greatest.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/drive-sdk/test/anki_greatest.h b/drive-sdk/test/anki_greatest.h
new file mode 100644
index 0000000..2d39a2b
--- /dev/null
+++ b/drive-sdk/test/anki_greatest.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Anki, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INCLUDE_anki_greatest_h__
+#define INCLUDE_anki_greatest_h__
+
+#define ANKI_GREATEST_HEX_DUMP(buffer, len) \
+ do { \
+ const uint8_t *b = (const uint8_t *)buffer; \
+ int i; \
+ for (i = 0; i < (len); ++i) { \
+ fprintf(GREATEST_STDOUT, "%02x ", b[i]); \
+ } \
+ } while(0)
+
+#define ANKI_GREATEST_ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN) \
+ do { \
+ const void *exp_s = (const void *)(EXP); \
+ const void *got_s = (const void *)(GOT); \
+ const size_t len_s = (const size_t)(LEN); \
+ greatest_info.msg = MSG; \
+ greatest_info.fail_file = __FILE__; \
+ greatest_info.fail_line = __LINE__; \
+ if (0 != memcmp(exp_s, got_s, len_s)) { \
+ fprintf(GREATEST_STDOUT, "Expected:\n####\n"); \
+ ANKI_GREATEST_HEX_DUMP(exp_s, len_s); \
+ fprintf(GREATEST_STDOUT, "\n####\n"); \
+ fprintf(GREATEST_STDOUT, "Got:\n####\n"); \
+ ANKI_GREATEST_HEX_DUMP(got_s, len_s); \
+ fprintf(GREATEST_STDOUT, "\n####\n"); \
+ return -1; \
+ } \
+ greatest_info.msg = NULL; \
+ } while (0)
+
+#define ANKI_GREATEST_ASSERT_BYTES_EQ(EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQm(#EXP " != " #GOT, EXP, GOT, LEN)
+
+#define ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQm(MSG, EXP, GOT, LEN)
+#define ASSERT_BYTES_EQ(EXP, GOT, LEN) ANKI_GREATEST_ASSERT_BYTES_EQ(EXP, GOT, LEN)
+
+#endif