summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2019-12-03 18:57:51 +1100
committerDonovan Baarda <abo@minkirri.apana.org.au>2019-12-03 18:57:51 +1100
commit43116b68c2a6ce33482188e77a16abea89409c3a (patch)
tree6a98ba514208bb0d1216354451805f4acab26641 /tests
parent23938bc63e3f58ea9d827c5f64967edcddf05ec8 (diff)
downloadlibrsync-43116b68c2a6ce33482188e77a16abea89409c3a.tar.gz
Tidy netint.[ch] and add tests.
Add tests/netint_test.c and CMakeLists.txt changes to test rs_int_len(). In netint.[ch] replace runtime checks for invalid arguments with assert() statements and tidy the argument names, variable names, and ordering. Replace `unsigned char` arguments with `rs_byte_t`. Add an assert to rs_int_len() to require the argument is positive.
Diffstat (limited to 'tests')
-rw-r--r--tests/netint_test.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/netint_test.c b/tests/netint_test.c
new file mode 100644
index 0000000..e25b582
--- /dev/null
+++ b/tests/netint_test.c
@@ -0,0 +1,49 @@
+/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * librsync -- dynamic caching and delta update in HTTP
+ *
+ * Copyright (C) 2019 by Donovan Baarda <abo@minkirri.apana.org.au>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* Force DEBUG on so that tests can use assert(). */
+#undef NDEBUG
+#include <assert.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include "librsync.h"
+#include "netint.h"
+
+/* Test driver for netint. */
+int main(int argc, char **argv)
+{
+ assert(rs_int_len((rs_long_t)0) == 1);
+ assert(rs_int_len((rs_long_t)1) == 1);
+ assert(rs_int_len((rs_long_t)INT8_MAX) == 1);
+ assert(rs_int_len((rs_long_t)1 << 7) == 1);
+ assert(rs_int_len((rs_long_t)1 << 8) == 2);
+ assert(rs_int_len((rs_long_t)INT16_MAX) == 2);
+#ifdef INT32_MAX
+ assert(rs_int_len((rs_long_t)1 << 15) == 2);
+ assert(rs_int_len((rs_long_t)1 << 16) == 4);
+ assert(rs_int_len((rs_long_t)INT32_MAX) == 4);
+#endif
+#ifdef INT64_MAX
+ assert(rs_int_len((rs_long_t)1 << 31) == 4);
+ assert(rs_int_len((rs_long_t)1 << 32) == 8);
+ assert(rs_int_len((rs_long_t)INT64_MAX) == 8);
+#endif
+ return 0;
+}