summaryrefslogtreecommitdiff
path: root/unittest/dockzen_api/dzl_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/dockzen_api/dzl_interface.cpp')
-rw-r--r--unittest/dockzen_api/dzl_interface.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/unittest/dockzen_api/dzl_interface.cpp b/unittest/dockzen_api/dzl_interface.cpp
new file mode 100644
index 0000000..4326a6a
--- /dev/null
+++ b/unittest/dockzen_api/dzl_interface.cpp
@@ -0,0 +1,123 @@
+#include <stdio.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include "dockzen_types.h"
+#include "dockzen.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+
+namespace testing {
+ namespace internal {
+ enum GTestColor {
+ COLOR_DEFAULT,
+ COLOR_RED,
+ COLOR_GREEN,
+ COLOR_YELLOW
+ };
+ extern void ColoredPrintf(GTestColor color, const char* fmt, ...);
+ }
+}
+#define PRINTF(...) do {\
+ testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[INFO ] ");\
+ testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, __VA_ARGS__);\
+ } while(0)
+
+TEST(dockzen_API, dockzen_API_dockzen_get_containers_info)
+{
+ int ret = DOCKZEN_ERROR_NOT_SUPPORTED;
+ int index = 0;
+ int error = 0;
+ int result = -1;
+ containers_info_s containers_info = {0, };
+
+ ret = dockzen_get_containers_info(&containers_info);
+
+ if (ret == DOCKZEN_ERROR_NONE) {
+
+ for (index = 0; index < containers_info.count; index++) {
+
+ if ((containers_info.container[index].id == NULL) ||
+ (containers_info.container[index].name == NULL) ||
+ (containers_info.container[index].image_name == NULL) ||
+ (containers_info.container[index].status == NULL)) {
+
+ error = 1;
+ } else {
+ PRINTF("container[%d].id: %s\n", index, containers_info.container[index].id);
+ PRINTF("container[%d].name: %s\n", index, containers_info.container[index].name);
+ PRINTF("container[%d].image_name: %s\n", index, containers_info.container[index].image_name);
+ PRINTF("container[%d].status: %s\n", index, containers_info.container[index].status);
+ }
+ }
+
+ if (error == 0) {
+ result = DOCKZEN_ERROR_NONE;
+ }
+ }
+
+ ASSERT_EQ(DOCKZEN_ERROR_NONE, result);
+}
+
+static void __update_container_cb(container_update_cb_s *status, void *user_data)
+{
+ PRINTF("container_update_cb\n");
+}
+
+TEST(dockzen_API, dockzen_API_dockzen_update_container)
+{
+ int error = 0;
+ int result = -1;
+ int ret = DOCKZEN_ERROR_NOT_SUPPORTED;
+ const char *const_container_name = "tizen";
+ const char *const_image_name = "10.113.62.204:443/headless:v0.2";
+ const char *const_user_data = "test";
+ void (*callback)(container_update_cb_s *, void *) = __update_container_cb;
+ char *user_data = NULL;
+ container_update_s container_update = {0, };
+ container_update_res_s container_update_res = {0, };
+
+ container_update.container_name = (char *)malloc(strlen(const_container_name) + 1);
+ container_update.image_name = (char *)malloc(strlen(const_image_name) + 1);
+ user_data = (char *)malloc(strlen(const_user_data) + 1);
+ memset(container_update.container_name, 0x00, strlen(const_container_name) + 1);
+ memset(container_update.image_name, 0x00, strlen(const_image_name) + 1);
+ strncpy(container_update.container_name, const_container_name, strlen(const_container_name));
+ strncpy(container_update.image_name, const_image_name, strlen(const_image_name));
+ strncpy(user_data, const_user_data, strlen(const_user_data));
+
+ ret = dockzen_update_container(&container_update, &container_update_res, callback, user_data);
+
+ if (!ret) {
+ if ((container_update_res.container_name == NULL) ||
+ (container_update_res.image_name_prev == NULL) ||
+ (container_update_res.image_name_new == NULL) ||
+ (container_update_res.status == NULL)) {
+
+ error = 1;
+ } else {
+ PRINTF("container_name: %s\n", container_update_res.container_name);
+ PRINTF("image_name_prev: %s\n", container_update_res.image_name_prev);
+ PRINTF("image_name_new: %s\n", container_update_res.image_name_new);
+ PRINTF("status: %s\n", container_update_res.status);
+ }
+
+ if (error == 0) {
+ result = DOCKZEN_ERROR_NONE;
+ }
+ }
+
+ free(container_update.container_name);
+ free(container_update.image_name);
+
+ ASSERT_EQ(DOCKZEN_ERROR_NONE, result);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}