diff options
Diffstat (limited to 'hicn-light/src/hicn/base/test')
-rw-r--r-- | hicn-light/src/hicn/base/test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/test/test-bitmap.cc | 87 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/test/test-hash.cc | 57 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/test/test-khash.cc | 139 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/test/test-pool.cc | 73 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/test/test-vector.cc | 97 |
6 files changed, 458 insertions, 0 deletions
diff --git a/hicn-light/src/hicn/base/test/CMakeLists.txt b/hicn-light/src/hicn/base/test/CMakeLists.txt index 03c5a89b5..351e7bd34 100644 --- a/hicn-light/src/hicn/base/test/CMakeLists.txt +++ b/hicn-light/src/hicn/base/test/CMakeLists.txt @@ -3,7 +3,12 @@ include(BuildMacros) list(APPEND TESTS + test-bitmap + test-hash + test-khash test-loop + test-pool + test-vector ) foreach(test ${TESTS}) diff --git a/hicn-light/src/hicn/base/test/test-bitmap.cc b/hicn-light/src/hicn/base/test/test-bitmap.cc new file mode 100644 index 000000000..4aee8a13f --- /dev/null +++ b/hicn-light/src/hicn/base/test/test-bitmap.cc @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * 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. + */ + +#include <gtest/gtest.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <netinet/in.h> + +extern "C" { +#include <hicn/base/vector.h> +#include <hicn/base/bitmap.h> +} + +class BitmapTest : public ::testing::Test { + protected: + BitmapTest() { + } + + virtual ~BitmapTest() { + + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + virtual void SetUp() { + bitmap_init(bitmap, 1024); + } + + virtual void TearDown() { + free(bitmap); + } + uint32_t *bitmap; +}; + +TEST_F(BitmapTest, BitmapSet) +{ + bitmap_set(bitmap, 20); + EXPECT_TRUE(bitmap_is_set(bitmap, 20) == true); + EXPECT_TRUE(bitmap_is_unset(bitmap, 20) == false); + EXPECT_TRUE(bitmap_is_set(bitmap, 19) == false); + EXPECT_TRUE(bitmap_is_unset(bitmap, 19) == true); + +} + +TEST_F(BitmapTest, BitmapUnSet) { + bitmap_set(bitmap, 20); + bitmap_set(bitmap, 19); + bitmap_unset(bitmap, 20); + EXPECT_TRUE(bitmap_is_set(bitmap, 20) == false); + EXPECT_TRUE(bitmap_is_unset(bitmap, 20) == true); + EXPECT_TRUE(bitmap_is_set(bitmap, 19) == true); + EXPECT_TRUE(bitmap_is_unset(bitmap, 19) == false); + +} + +TEST_F(BitmapTest, BitmapSetTo) { + bitmap_set_to(bitmap, 40); + EXPECT_TRUE(bitmap_is_set(bitmap, 20) == true); + EXPECT_TRUE(bitmap_is_set(bitmap, 21) == true); + EXPECT_TRUE(bitmap_is_unset(bitmap, 41) == true); + EXPECT_TRUE(bitmap_is_unset(bitmap, 42) == true); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/hicn-light/src/hicn/base/test/test-hash.cc b/hicn-light/src/hicn/base/test/test-hash.cc new file mode 100644 index 000000000..78e318794 --- /dev/null +++ b/hicn-light/src/hicn/base/test/test-hash.cc @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * 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. + */ + +#include <gtest/gtest.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <netinet/in.h> + +extern "C" { +#include <hicn/base/hash.h> +} + +class HashTest : public ::testing::Test { + protected: + HashTest() { + } + + virtual ~HashTest() { + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + virtual void SetUp() { + // Code here will be called immediately after the constructor (right + // before each test). + } + + virtual void TearDown() { + // Code here will be called immediately after each test (right + // before the destructor). + } +}; + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/hicn-light/src/hicn/base/test/test-khash.cc b/hicn-light/src/hicn/base/test/test-khash.cc new file mode 100644 index 000000000..798063ca5 --- /dev/null +++ b/hicn-light/src/hicn/base/test/test-khash.cc @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * 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. + */ + +#include <gtest/gtest.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <netinet/in.h> + +extern "C" { +#include <hicn/base/khash.h> + +} + +KHASH_MAP_INIT_INT(int, unsigned char) + +typedef struct { + unsigned key; + unsigned char val; +} int_unpack_t; + +typedef struct { + unsigned key; + unsigned char val; +} __attribute__ ((__packed__)) int_packed_t; + +#define hash_eq(a, b) ((a).key == (b).key) +#define hash_func(a) ((a).key) + +KHASH_INIT(iun, int_unpack_t, char, 0, hash_func, hash_eq) +KHASH_INIT(ipk, int_packed_t, char, 0, hash_func, hash_eq) + +class KHashTest : public ::testing::Test { + protected: + KHashTest() { + } + + virtual ~KHashTest() { + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + virtual void SetUp() { + + khash = kh_init(int); + } + + virtual void TearDown() { + + kh_destroy(int, khash); + + } + khash_t(int) *khash; +}; + + +TEST_F(KHashTest, KhashIntSize) +{ + int ret; + int k; + int size = kh_size(khash); + + EXPECT_EQ(size, 0); + k = kh_put(int, khash, 10, &ret); + if (ret == 1) { + kh_val(khash, k) = 10; + } + size = kh_size(khash); + EXPECT_EQ(size, 1); + +} + +TEST_F(KHashTest, KhashIntPut) +{ + int ret; + int k; + k = kh_put(int, khash, 10, &ret); + if (ret == 1) { + kh_val(khash, k) = 10; + } + int size = kh_size(khash); + EXPECT_EQ(size, 1); + k = kh_put(int, khash, 20, &ret); + if (ret == 1) { + kh_val(khash, k) = 20; + } + size = kh_size(khash); + EXPECT_EQ(size, 2); +} + +TEST_F(KHashTest, KhashCheckValue) +{ + int ret; + int k; + k = kh_put(int, khash, 10, &ret); + if (ret == 1) { + kh_val(khash, k) = 100; + } + k = kh_put(int, khash, 20, &ret); + if (ret == 1) { + kh_val(khash, k) = 200; + } + + k = kh_put(int, khash, 10, &ret); + int val = -1; + if (!ret) + val = kh_val(khash, k); + EXPECT_EQ(val, 100); + + k = kh_put(int, khash, 20, &ret); + val = -1; + if (!ret) + val = kh_val(khash, k); + EXPECT_EQ(val, 200); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/hicn-light/src/hicn/base/test/test-pool.cc b/hicn-light/src/hicn/base/test/test-pool.cc new file mode 100644 index 000000000..86c1c1270 --- /dev/null +++ b/hicn-light/src/hicn/base/test/test-pool.cc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * 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. + */ + +#include <gtest/gtest.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <netinet/in.h> + +extern "C" { +#include <hicn/base/pool.h> +} + +class PoolTest : public ::testing::Test { + protected: + PoolTest() { + } + + virtual ~PoolTest() { + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + virtual void SetUp() { + + } + + virtual void TearDown() { + pool_free(pool); + } + + int *pool; +}; + +TEST_F(PoolTest, PoolPut) +{ + pool_init(pool, 1024); + int* elt; + pool_get(pool, elt); + *elt = 10; + printf("2\n"); + pool_put(pool, elt); + printf("3\n"); + + //pool_get(pool) + //loop_ = loop_create(); + //EXPECT_TRUE(loop_ != NULL); +} + + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/hicn-light/src/hicn/base/test/test-vector.cc b/hicn-light/src/hicn/base/test/test-vector.cc new file mode 100644 index 000000000..71b38a2b6 --- /dev/null +++ b/hicn-light/src/hicn/base/test/test-vector.cc @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * 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. + */ + +#include <gtest/gtest.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <netinet/in.h> + +extern "C" { +#include <hicn/base/vector.h> +} + +class VectorTest : public ::testing::Test { + protected: + VectorTest() { + } + + virtual ~VectorTest() { + // You can do clean-up work that doesn't throw exceptions here. + } + + // If the constructor and destructor are not enough for setting up + // and cleaning up each test, you can define the following methods: + + virtual void SetUp() {; + vector_init(vector, 1024); + } + + virtual void TearDown() { + vector_free(vector); + } + + int *vector = NULL; + +}; + +TEST_F(VectorTest, VectorSize) +{ + vector_push(vector, 109); + vector_push(vector, 109); + int size = vector_len(vector); + EXPECT_EQ(size, 2); + vector_push(vector, 109); + size = vector_len(vector); + EXPECT_EQ(size, 3); + +} + +TEST_F(VectorTest, VectorCheckValue) +{ + vector_push(vector, 109); + vector_push(vector, 200); + EXPECT_EQ(vector[0], 109); + EXPECT_EQ(vector[1], 200); + +} + +TEST_F(VectorTest, VectorEnsurePos) +{ + printf (" %p\n", vector); + vector_ensure_pos(vector, 1025); + for (int i = 0; i <1025; i++) { + printf("i %d\n", i); + printf (" %p\n", vector); + + + vector_push(vector, i); + + } + int size = vector_len(vector); + EXPECT_EQ(size, 1025); +} + + + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} |