aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-10-03 12:06:47 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-10-03 12:06:47 +0200
commit5687d6e79a3ded310c847177d3a200384fdeb3d9 (patch)
tree23bddcf5867ec73089892ff3bebf7a2a24e47474 /tests
parenta9ec8b055f2e49258eafe3a6e5a497a9db6d6184 (diff)
downloadlibssh-5687d6e79a3ded310c847177d3a200384fdeb3d9.tar.gz
libssh-5687d6e79a3ded310c847177d3a200384fdeb3d9.tar.xz
libssh-5687d6e79a3ded310c847177d3a200384fdeb3d9.zip
Added buffer test case
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/CMakeLists.txt1
-rw-r--r--tests/unittests/torture_buffer.c67
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt
index 394fab2f..52efbc52 100644
--- a/tests/unittests/CMakeLists.txt
+++ b/tests/unittests/CMakeLists.txt
@@ -1,5 +1,6 @@
project(unittests C)
+add_check_test(torture_buffer torture_buffer.c ${TORTURE_LIBRARY})
add_check_test(torture_callbacks torture_callbacks.c ${TORTURE_LIBRARY})
add_check_test(torture_init torture_init.c ${TORTURE_LIBRARY})
add_check_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY})
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
new file mode 100644
index 00000000..a64c5a71
--- /dev/null
+++ b/tests/unittests/torture_buffer.c
@@ -0,0 +1,67 @@
+#define LIBSSH_STATIC
+
+#include "torture.h"
+#include "libssh/buffer.h"
+
+ssh_buffer buffer;
+#define LIMIT (8*1024*1024)
+
+static void setup(void) {
+ buffer=ssh_buffer_new();
+}
+
+static void teardown(void) {
+ ssh_buffer_free(buffer);
+}
+
+/* test if the continuously growing buffer size never exceeds 2 time its
+ * real capacity
+ */
+START_TEST (torture_growing_buffer)
+{
+ int i;
+ for(i=0;i<LIMIT;++i){
+ buffer_add_data(buffer,"A",1);
+ if(buffer->used >= 128){
+ if(buffer_get_rest_len(buffer) * 2 < buffer->allocated){
+ ck_assert(buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
+ }
+ }
+ }
+}
+END_TEST
+
+/* test if the continuously growing buffer size never exceeds 2 time its
+ * real capacity, when we remove 1 byte after each call (sliding window)
+ */
+START_TEST (torture_growing_buffer_shifting)
+{
+ int i;
+ unsigned char c;
+ for(i=0; i<1024;++i){
+ buffer_add_data(buffer,"S",1);
+ }
+ for(i=0;i<LIMIT;++i){
+ buffer_get_u8(buffer,&c);
+ buffer_add_data(buffer,"A",1);
+ if(buffer->used >= 128){
+ if(buffer_get_rest_len(buffer) * 4 < buffer->allocated){
+ ck_assert(buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
+ return;
+ }
+ }
+ }
+}
+END_TEST
+
+Suite *torture_make_suite(void) {
+ Suite *s = suite_create("libssh_buffer");
+
+ torture_create_case_fixture(s, "torture_growing_buffer",
+ torture_growing_buffer, setup, teardown);
+ torture_create_case_fixture(s, "torture_growing_buffer_shifting",
+ torture_growing_buffer_shifting, setup, teardown);
+
+ return s;
+}
+