You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/05/27 18:36:51 UTC
[08/51] [partial] celix git commit: CELIX-424: Cleans up the
directory structure. Moves all libraries to the libs subdir and all bundles
to the bundles subdir
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/bundle_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/bundle_test.cpp b/framework/private/test/bundle_test.cpp
deleted file mode 100644
index 57ac1e2..0000000
--- a/framework/private/test/bundle_test.cpp
+++ /dev/null
@@ -1,1053 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * bundle_test.cpp
- *
- * \date Feb 11, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-#include "string.h"
-
-extern "C" {
-#include "bundle_revision_private.h"
-#include "bundle_private.h"
-#include "utils.h"
-#include "celix_log.h"
-
-framework_logger_pt logger = (framework_logger_pt) 0x42;
-}
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
-
-TEST_GROUP(bundle) {
- void setup(void) {
- }
-
- void teardown(void) {
- mock().checkExpectations();
- mock().clear();
- }
-};
-
-static char* my_strdup(const char* s) {
- if (s == NULL) {
- return NULL;
- }
-
- size_t len = strlen(s);
-
- char *d = (char*) calloc(len + 1, sizeof(char));
-
- if (d == NULL) {
- return NULL;
- }
-
- strncpy(d, s, len);
- return d;
-}
-
-
-TEST(bundle, create) {
- bundle_archive_pt archive = (bundle_archive_pt) 0x10;
- mock().expectOneCall("bundleArchive_createSystemBundleArchive")
- .withOutputParameterReturning("bundle_archive", &archive, sizeof(archive))
- .andReturnValue(CELIX_SUCCESS);
-
- module_pt module = (module_pt) 0x20;
- mock().expectOneCall("module_createFrameworkModule")
- .ignoreOtherParameters()
- .andReturnValue(module);
-
- mock().expectOneCall("resolver_addModule")
- .withParameter("module", module);
-
- bundle_pt actual = NULL;
- celix_status_t status = bundle_create(&actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(NULL, actual->context);
- POINTERS_EQUAL(NULL, actual->activator);
- LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, actual->state);
- POINTERS_EQUAL(NULL, actual->handle);
- POINTERS_EQUAL(archive, actual->archive);
- CHECK(actual->modules);
- POINTERS_EQUAL(NULL, actual->manifest);
- // CHECK(actual->lock)
- LONGS_EQUAL(0, actual->lockCount);
- POINTERS_EQUAL(NULL, actual->lockThread.thread);
- POINTERS_EQUAL(NULL, actual->framework);
-
- mock().expectOneCall("module_destroy");
- bundle_destroy(actual);
-}
-
-TEST(bundle, createFromArchive) {
- framework_pt framework = (framework_pt) 0x10;
- bundle_archive_pt archive = (bundle_archive_pt) 0x20;
- bundle_revision_pt revision = (bundle_revision_pt) 0x21;
- manifest_pt manifest = (manifest_pt) 0x30;
-
- mock().expectOneCall("bundleArchive_getCurrentRevision")
- .withParameter("archive", archive)
- .withOutputParameterReturning("revision", &revision, sizeof(revision))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("bundleRevision_getManifest")
- .withParameter("revision", revision)
- .withOutputParameterReturning("manifest", &manifest, sizeof(manifest))
- .andReturnValue(CELIX_SUCCESS);
-
- long id = 1;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- module_pt module = (module_pt) 0x40;
- mock().expectOneCall("module_create")
- .withParameter("headerMap", manifest)
- // .withParameter("moduleId", "1.0")
- // .withParameter("bundle", (void *) 0x40)
- .ignoreOtherParameters()
- .andReturnValue(module);
-
- version_pt version = (version_pt) 0x50;
- mock().expectOneCall("module_getVersion")
- .withParameter("module", module)
- .andReturnValue(version);
-
- char symbolicName[] = "name";
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", module)
- .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(symbolicName))
- .andReturnValue(CELIX_SUCCESS);
-
- array_list_pt bundles = NULL;
- arrayList_create(&bundles);
- mock().expectOneCall("framework_getBundles")
- .withParameter("framework", framework)
- .andReturnValue(bundles);
-
- mock().expectOneCall("resolver_addModule")
- .withParameter("module", module);
-
- bundle_pt actual = NULL;
- celix_status_t status = bundle_createFromArchive(&actual, framework, archive);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(NULL, actual->context);
- POINTERS_EQUAL(NULL, actual->activator);
- LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, actual->state);
- POINTERS_EQUAL(NULL, actual->handle);
- POINTERS_EQUAL(archive, actual->archive);
- CHECK(actual->modules);
- POINTERS_EQUAL(NULL, actual->manifest);
- // CHECK(actual->lock)
- LONGS_EQUAL(0, actual->lockCount);
- POINTERS_EQUAL(NULL, actual->lockThread.thread);
- POINTERS_EQUAL(framework, actual->framework);
-
- arrayList_destroy(actual->modules);
- free(actual);
-
-
- mock().clear();
-}
-
-TEST(bundle, getArchive) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_archive_pt archive = (bundle_archive_pt) 0x10;
- bundle->archive = archive;
-
- bundle_archive_pt actual = NULL;
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getArchive(bundle, &actual));
- POINTERS_EQUAL(archive, actual);
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- actual = NULL;
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_getArchive(NULL, &actual));
-
- free(bundle);
-
-
- mock().clear();
-}
-
-TEST(bundle, getCurrentModule) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- module_pt module1 = (module_pt) 0x11;
- module_pt module2 = (module_pt) 0x12;
- module_pt module3 = (module_pt) 0x13;
- module_pt module4 = (module_pt) 0x14;
- arrayList_create(&bundle->modules);
- arrayList_add(bundle->modules, module1);
- arrayList_add(bundle->modules, module2);
- arrayList_add(bundle->modules, module3);
- arrayList_add(bundle->modules, module4);
-
- module_pt actual = NULL;
- celix_status_t status = bundle_getCurrentModule(bundle, &actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(module4, actual);
-
- actual = NULL;
- status = bundle_getCurrentModule(NULL, &actual);
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
-
- arrayList_destroy(bundle->modules);
- free(bundle);
-}
-
-TEST(bundle, getModules) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- array_list_pt modules = (array_list_pt) 0x10;
- bundle->modules = modules;
-
- array_list_pt actual = bundle_getModules(bundle);
- POINTERS_EQUAL(modules, actual);
-
- free(bundle);
-}
-
-TEST(bundle, getHandle) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- void *expected = (void *) 0x10;
- bundle->handle = expected;
-
- void *actual = bundle_getHandle(bundle);
- POINTERS_EQUAL(expected, actual);
-
- free(bundle);
-}
-
-TEST(bundle, setHandle) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- void *expected = (void *) 0x10;
-
- bundle_setHandle(bundle, expected);
- POINTERS_EQUAL(expected, bundle->handle);
-
- free(bundle);
-}
-
-TEST(bundle, getActivator) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- activator_pt expected = (activator_pt) 0x10;
- bundle->activator = expected;
-
- activator_pt actual = bundle_getActivator(bundle);
- POINTERS_EQUAL(expected, actual);
-
- free(bundle);
-}
-
-TEST(bundle, setActivator) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- activator_pt expected = (activator_pt) 0x10;
-
- celix_status_t status = bundle_setActivator(bundle, expected);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(expected, bundle->activator);
-
- free(bundle);
-}
-
-TEST(bundle, getContext) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_context_pt expected = (bundle_context_pt) 0x10;
- bundle->context = expected;
-
- bundle_context_pt actual = NULL;
- celix_status_t status = bundle_getContext(bundle, &actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(expected, actual);
-
- free(bundle);
-}
-
-TEST(bundle, setContext) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_context_pt expected = (bundle_context_pt) 0x10;
-
- celix_status_t status = bundle_setContext(bundle, expected);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(expected, bundle->context);
-
- free(bundle);
-}
-
-TEST(bundle, getEntry) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle->framework = framework;
-
- char name[] = "name";
- char *expected = (char *) 0x20;
- mock().expectOneCall("framework_getBundleEntry")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("name", name)
- .withOutputParameterReturning("entry", &expected, sizeof(expected))
- .andReturnValue(CELIX_SUCCESS);
-
- char *actual = NULL;
- celix_status_t status = bundle_getEntry(bundle, name, &actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(expected, actual);
-
- //free(actual);
- free(bundle);
-}
-
-TEST(bundle, getState) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle->state = OSGI_FRAMEWORK_BUNDLE_ACTIVE;
-
- bundle_state_e actual = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getState(bundle, &actual));
- POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, actual);
-
- //get unknown bundle's state
- LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_getState((bundle_pt)NULL, &actual));
- POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_UNKNOWN, actual);
-
- free(bundle);
-}
-
-TEST(bundle, setState) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle->state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
-
- celix_status_t status = bundle_setState(bundle, OSGI_FRAMEWORK_BUNDLE_INSTALLED);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, bundle->state);
-
- free(bundle);
-}
-
-/*//declared here, since its non-static, but not actually exported by bundle.h or bundle_private.h
-extern celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module);
-
-TEST(bundle, createModule){
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
-
- module_pt module = (module_pt) 0x01;
- module_pt module2 = (module_pt) 0x02;
- module_pt module3 = (module_pt) 0x03;
- arrayList_create(&bundle->modules);
- arrayList_add(bundle->modules, module);
- arrayList_add(bundle->modules, module2);
- arrayList_add(bundle->modules, module3);
-
- framework_pt framework = (framework_pt) 0x04;
- bundle->framework = framework;
-
- bundle_archive_pt archive = (bundle_archive_pt) 0x05;
- bundle->archive = archive;
-
- module_pt module_new = (module_pt) 0x06;
- bundle_revision_pt revision = (bundle_revision_pt) 0x07;
- version_pt version = (version_pt) 0x08;
- manifest_pt manifest = (manifest_pt) 0x09;
-
- long id = 666;
- char * symbolicName = my_strdup("name");
-
- bundle_pt bundle2 = (bundle_pt) malloc(sizeof(*bundle));
- module_pt module4 = (module_pt) 0x0A;
- arrayList_create(&bundle2->modules);
- arrayList_add(bundle2->modules, module4);
- bundle2->framework = framework;
-
- bundle_archive_pt archive2 = (bundle_archive_pt) 0x0B;
- bundle2->archive = archive2;
-
- version_pt version2 = (version_pt) 0x0C;
- long id2 = 667;
-
- array_list_pt bundles;
- arrayList_create(&bundles);
- arrayList_add(bundles, bundle2);
-
- //expected calls from bundle_createModule
- mock().expectOneCall("bundleArchive_getCurrentRevision")
- .withParameter("archive", archive)
- .withOutputParameterReturning("revision", &revision, sizeof(revision));
-
- mock().expectOneCall("bundleRevision_getManifest")
- .withParameter("revision", revision)
- .withOutputParameterReturning("manifest", &manifest, sizeof(manifest));
-
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id));
-
- mock().expectOneCall("module_create")
- .withParameter("headerMap", manifest)
- .withParameter("moduleId", "666.0")
- .withParameter("bundle", bundle)
- .andReturnValue(module_new);
-
- mock().expectOneCall("module_getVersion")
- .withParameter("module", module_new)
- .andReturnValue(version);
-
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", module_new)
- .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*));
-
- mock().expectOneCall("framework_getBundles")
- .withParameter("framework", framework)
- .andReturnValue(bundles);
-
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive2)
- .withOutputParameterReturning("id", &id2, sizeof(id2));
-
- //returning same symbolic name for module_new as for module4
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", module4)
- .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*));
-
- //returning different version for module_new as for module4
- mock().expectOneCall("module_getVersion")
- .withParameter("module", module4)
- .andReturnValue(version2);
-
- int result = 1; //1 means not equal
- mock().expectOneCall("version_compareTo")
- .withParameter("version", version)
- .withParameter("compare", version2)
- .withOutputParameterReturning("result", &result,sizeof(result));
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_createModule(bundle, &module_new));
-
- arrayList_destroy(bundle->modules);
- arrayList_destroy(bundle2->modules);
-
- free(bundle);
- free(bundle2);
- free(symbolicName);
-}*/
-
-TEST(bundle, start) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle_archive_pt archive = (bundle_archive_pt) 0x20;
- bundle->framework = framework;
- bundle->archive = archive;
-
- int options = 42;
-
- long id = 1;
- mock().expectNCalls(2, "bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("fw_startBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("options", options)
- .andReturnValue(CELIX_SUCCESS);
-
- celix_status_t status = bundle_startWithOptions(bundle, options);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- mock().expectOneCall("fw_startBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("options", 0)
- .andReturnValue(CELIX_SUCCESS);
-
- status = bundle_start(bundle);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- free(bundle);
-}
-
-TEST(bundle, update) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle_archive_pt archive = (bundle_archive_pt) 0x20;
- bundle->framework = framework;
- bundle->archive = archive;
-
- long id = 1;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- char input[] = "input";
- mock().expectOneCall("framework_updateBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("inputFile", input)
- .andReturnValue(CELIX_SUCCESS);
-
- celix_status_t status = bundle_update(bundle, input);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- free(bundle);
-}
-
-TEST(bundle, stop) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle_archive_pt archive = (bundle_archive_pt) 0x20;
- bundle->framework = framework;
- bundle->archive = archive;
-
- long id = 1;
- mock().expectNCalls(2, "bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- int options = 1;
- mock().expectOneCall("fw_stopBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("record", 1)
- .andReturnValue(CELIX_SUCCESS);
-
- celix_status_t status = bundle_stopWithOptions(bundle, options);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- mock().expectOneCall("fw_stopBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withParameter("record", 0)
- .andReturnValue(CELIX_SUCCESS);
-
- status = bundle_stop(bundle);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- free(bundle);
-}
-
-TEST(bundle, uninstall) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle_archive_pt archive = (bundle_archive_pt) 0x20;
- bundle->framework = framework;
- bundle->archive = archive;
-
- long id = 666;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("fw_uninstallBundle")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .andReturnValue(CELIX_SUCCESS);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_uninstall(bundle));
-
- //attempt to uninstall framework bundle
- id = 0;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_BUNDLE_EXCEPTION);
-
- LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_uninstall(bundle));
-
- free(bundle);
-}
-
-TEST(bundle, setPersistentStateInactive) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_archive_pt archive = (bundle_archive_pt) 0x10;
- bundle->archive = archive;
-
- long id = 1;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("bundleArchive_setPersistentState")
- .withParameter("archive", archive)
- .withParameter("state", OSGI_FRAMEWORK_BUNDLE_INSTALLED)
- .andReturnValue(CELIX_SUCCESS);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_setPersistentStateInactive(bundle));
-
- free(bundle);
-}
-
-TEST(bundle, setPersistentStateUninstalled) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_archive_pt archive = (bundle_archive_pt) 0x10;
- bundle->archive = archive;
-
- long id = 1;
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id))
- .andReturnValue(CELIX_SUCCESS);
-
- mock().expectOneCall("bundleArchive_setPersistentState")
- .withParameter("archive", archive)
- .withParameter("state", OSGI_FRAMEWORK_BUNDLE_UNINSTALLED)
- .andReturnValue(CELIX_SUCCESS);
-
- celix_status_t status = bundle_setPersistentStateUninstalled(bundle);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- free(bundle);
-}
-
-TEST(bundle, revise) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- arrayList_create(&bundle->modules);
- bundle_archive_pt actual_archive = (bundle_archive_pt) 0x02;
- bundle_revision_pt actual_revision = (bundle_revision_pt) malloc(sizeof(*actual_revision));
- manifest_pt actual_manifest = (manifest_pt) malloc(sizeof(*actual_manifest));
- int actual_id = 666;
- const char * actual_module_id = "666.0";
- bundle->archive = actual_archive;
- char * symbolic_name = NULL;
- char location[] = "location";
- char inputFile[] = "inputFile";
-
- mock().expectNCalls(2, "bundleArchive_revise")
- .withParameter("archive", actual_archive)
- .withParameter("location", location)
- .withParameter("inputFile", inputFile);
-
- mock().expectNCalls(2, "bundleArchive_getCurrentRevision")
- .withParameter("archive", bundle->archive)
- .withOutputParameterReturning("revision", &actual_revision, sizeof(actual_revision));
-
- mock().expectNCalls(2, "bundleRevision_getManifest")
- .withParameter("revision", actual_revision)
- .withOutputParameterReturning("manifest", &actual_manifest, sizeof(actual_manifest));
-
- mock().expectNCalls(2, "bundleArchive_getId")
- .withParameter("archive", actual_archive)
- .withOutputParameterReturning("id", &actual_id, sizeof(actual_id));
-
- mock().expectOneCall("module_create")
- .withParameter("headerMap", actual_manifest)
- .withParameter("moduleId", actual_module_id)
- .withParameter("bundle", bundle)
- .andReturnValue((void*)NULL);
-
- //module create returns NULL during test
- mock().expectOneCall("resolver_addModule")
- .withParameter("module", (void*)NULL);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_revise(bundle, location, inputFile));
-
- mock().expectOneCall("module_create")
- .withParameter("headerMap", actual_manifest)
- .withParameter("moduleId", actual_module_id)
- .withParameter("bundle", bundle)
- .andReturnValue((void*)0x01);
-
- mock().expectOneCall("module_getVersion")
- .withParameter("module", (void*)0x01);
-
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", (void*)0x01)
- .withOutputParameterReturning("symbolicName", &symbolic_name,sizeof(symbolic_name))
- .andReturnValue(CELIX_ILLEGAL_ARGUMENT);
-
- bool rolledBack = true;
- mock().expectOneCall("bundleArchive_rollbackRevise")
- .withParameter("archive", actual_archive)
- .withOutputParameterReturning("rolledback", &rolledBack, sizeof(rolledBack));
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_BUNDLE_EXCEPTION);
-
- LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_revise(bundle, location, inputFile));
-
- arrayList_destroy(bundle->modules);
- free(bundle);
- free(actual_revision);
- free(actual_manifest);
-}
-
-TEST(bundle, isLockable) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- celixThreadMutex_create(&bundle->lock, NULL);
- bundle->lockCount = 0;
-
- bool lockable = false;
- celix_status_t status = bundle_isLockable(bundle, &lockable);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- // FAIL("Test not fully implemented");
-
- free(bundle);
-}
-
-
-TEST(bundle, lockingThread) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- celixThreadMutex_create(&bundle->lock, NULL);
- celix_thread_t thread;
-
- bundle->lockCount = 0;
-
- bool locked = false;
- LONGS_EQUAL(CELIX_SUCCESS, bundle_lock(bundle, &locked));
- CHECK(locked);
- LONGS_EQUAL(1, bundle->lockCount);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getLockingThread(bundle, &thread));
- bool equals;
- thread_equalsSelf(thread, &equals);
- CHECK(equals);
-
- bool unlocked;
- bundle->lockCount = 1;
- LONGS_EQUAL(CELIX_SUCCESS, bundle_unlock(bundle, &unlocked));
- CHECK(unlocked);
- LONGS_EQUAL(0, bundle->lockCount);
-
- //try to unlock unlocked lock
- LONGS_EQUAL(CELIX_SUCCESS, bundle_unlock(bundle, &unlocked));
- CHECK_FALSE(unlocked);
- LONGS_EQUAL(0, bundle->lockCount);
-
- celixThreadMutex_destroy(&bundle->lock);
- free(bundle);
-}
-
-TEST(bundle, close) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
-
- module_pt module = (module_pt) 0x01;
- module_pt module2 = (module_pt) 0x02;
- module_pt module3 = (module_pt) 0x03;
- arrayList_create(&bundle->modules);
- arrayList_add(bundle->modules, module);
- arrayList_add(bundle->modules, module2);
- arrayList_add(bundle->modules, module3);
-
- bundle_archive_pt archive = (bundle_archive_pt) 0x05;
- bundle->archive = archive;
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module2);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module3);
-
- mock().expectNCalls(3, "module_setWires");
-
- mock().expectOneCall("bundleArchive_close")
- .withParameter("archive", archive);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_close(bundle));
-
- arrayList_destroy(bundle->modules);
- free(bundle);
-}
-
-TEST(bundle, closeAndDelete) {
- bundle_archive_pt archive = (bundle_archive_pt) 0x10;
- mock().expectOneCall("bundleArchive_createSystemBundleArchive")
- .withOutputParameterReturning("bundle_archive", &archive, sizeof(archive))
- .andReturnValue(CELIX_SUCCESS);
-
- module_pt module = (module_pt) 0x20;
- mock().expectOneCall("module_createFrameworkModule")
- .ignoreOtherParameters()
- .andReturnValue(module);
-
- mock().expectOneCall("resolver_addModule")
- .withParameter("module", module);
-
- bundle_pt actual = NULL;
- celix_status_t status = bundle_create(&actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module);
-
- mock().expectOneCall("module_setWires");
-
- mock().expectOneCall("bundleArchive_closeAndDelete");
-
- status = bundle_closeAndDelete(actual);
- LONGS_EQUAL(CELIX_SUCCESS, status);
-
- arrayList_destroy(actual->modules);
- free(actual);
-}
-
-TEST(bundle, closeModules) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- module_pt module = (module_pt) 0x01;
- module_pt module2 = (module_pt) 0x02;
- module_pt module3 = (module_pt) 0x03;
-
- arrayList_create(&bundle->modules);
- arrayList_add(bundle->modules, module);
- arrayList_add(bundle->modules, module2);
- arrayList_add(bundle->modules, module3);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module2);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module3);
-
- mock().expectNCalls(3, "module_setWires");
-
- bundle_closeModules(bundle);
-
- arrayList_destroy(bundle->modules);
- free(bundle);
-}
-
-TEST(bundle, refresh) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
-
- module_pt module = (module_pt) 0x01;
- module_pt module2 = (module_pt) 0x02;
- module_pt module3 = (module_pt) 0x03;
- arrayList_create(&bundle->modules);
- arrayList_add(bundle->modules, module);
- arrayList_add(bundle->modules, module2);
- arrayList_add(bundle->modules, module3);
-
- framework_pt framework = (framework_pt) 0x04;
- bundle->framework = framework;
-
- bundle_archive_pt archive = (bundle_archive_pt) 0x05;
- bundle->archive = archive;
-
- module_pt module_new = (module_pt) 0x06;
- bundle_revision_pt revision = (bundle_revision_pt) 0x07;
- version_pt version = (version_pt) 0x08;
- manifest_pt manifest = (manifest_pt) 0x09;
-
- long id = 666;
- char * symbolicName = my_strdup("name");
-
- bundle_pt bundle2 = (bundle_pt) malloc(sizeof(*bundle));
- module_pt module4 = (module_pt) 0x0A;
- arrayList_create(&bundle2->modules);
- arrayList_add(bundle2->modules, module4);
- bundle2->framework = framework;
-
- bundle_archive_pt archive2 = (bundle_archive_pt) 0x0B;
- bundle2->archive = archive2;
-
- version_pt version2 = (version_pt) 0x0C;
- long id2 = 667;
-
- array_list_pt bundles;
- arrayList_create(&bundles);
- arrayList_add(bundles, bundle2);
-
- //expected calls from bundle_refresh
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module2);
-
- mock().expectOneCall("resolver_removeModule")
- .withParameter("module", module3);
-
- mock().expectNCalls(3, "module_setWires");
-
- //expected calls from bundle_createModule
- mock().expectOneCall("bundleArchive_getCurrentRevision")
- .withParameter("archive", archive)
- .withOutputParameterReturning("revision", &revision, sizeof(revision));
-
- mock().expectOneCall("bundleRevision_getManifest")
- .withParameter("revision", revision)
- .withOutputParameterReturning("manifest", &manifest, sizeof(manifest));
-
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive)
- .withOutputParameterReturning("id", &id, sizeof(id));
-
- mock().expectOneCall("module_create")
- .withParameter("headerMap", manifest)
- .withParameter("moduleId", "666.0")
- .withParameter("bundle", bundle)
- .andReturnValue(module_new);
-
- mock().expectOneCall("module_getVersion")
- .withParameter("module", module_new)
- .andReturnValue(version);
-
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", module_new)
- .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*));
-
- mock().expectOneCall("framework_getBundles")
- .withParameter("framework", framework)
- .andReturnValue(bundles);
-
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", archive2)
- .withOutputParameterReturning("id", &id2, sizeof(id2));
-
- //returning same symbolic name for module_new as for module4
- mock().expectOneCall("module_getSymbolicName")
- .withParameter("module", module4)
- .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*));
-
- //returning different version for module_new as for module4
- mock().expectOneCall("module_getVersion")
- .withParameter("module", module4)
- .andReturnValue(version2);
-
- int result = 1; //1 means not equal
- mock().expectOneCall("version_compareTo")
- .withParameter("version", version)
- .withParameter("compare", version2)
- .withOutputParameterReturning("result", &result,sizeof(result));
-
- //expected calls from bundle_addModule
- mock().expectOneCall("resolver_addModule")
- .withParameter("module", module_new);
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_refresh(bundle));
-
- arrayList_destroy(bundle->modules);
- arrayList_destroy(bundle2->modules);
-
- free(bundle);
- free(bundle2);
- free(symbolicName);
-}
-
-TEST(bundle, getBundleId) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- bundle_archive_pt actual_archive = (bundle_archive_pt) 0x42;
- bundle->archive = actual_archive;
- long actual_id = 666;
- long get_id = 0;
-
- mock().expectOneCall("bundleArchive_getId")
- .withParameter("archive", actual_archive)
- .withOutputParameterReturning("id", &actual_id, sizeof(actual_id));
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getBundleId(bundle, &get_id));
- LONGS_EQUAL(actual_id, get_id);
-
- free(bundle);
-}
-
-TEST(bundle, getRegisteredServices) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle->framework = framework;
- array_list_pt list = (array_list_pt) 0x20;
- array_list_pt get = NULL;
-
- mock().expectOneCall("fw_getBundleRegisteredServices")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withOutputParameterReturning("services", &list, sizeof(list));
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getRegisteredServices(bundle, &get));
- POINTERS_EQUAL(list, get);
-
- free(bundle);
-}
-
-TEST(bundle, getServicesInUse) {
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
- framework_pt framework = (framework_pt) 0x10;
- bundle->framework = framework;
- array_list_pt list = (array_list_pt) 0x20;
- array_list_pt get = NULL;
-
- mock().expectOneCall("fw_getBundleServicesInUse")
- .withParameter("framework", framework)
- .withParameter("bundle", bundle)
- .withOutputParameterReturning("services", &list, sizeof(list));
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getServicesInUse(bundle, &get));
- POINTERS_EQUAL(list, get);
-
- free(bundle);
-}
-
-TEST(bundle, setFramework) {
- framework_pt framework = (framework_pt) 0x666;
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_setFramework(bundle, framework));
- POINTERS_EQUAL(framework, bundle->framework);
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_setFramework(bundle, NULL));
-
- free(bundle);
-}
-
-TEST(bundle, getFramework) {
- framework_pt get = NULL;
- framework_pt actual = (framework_pt) 0x666;
- bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
-
- bundle->framework = actual;
-
- LONGS_EQUAL(CELIX_SUCCESS, bundle_getFramework(bundle, &get));
-
- free(bundle);
- bundle = NULL;
-
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_getFramework(bundle, &get));
-
- free(bundle);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/capability_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/capability_test.cpp b/framework/private/test/capability_test.cpp
deleted file mode 100644
index f948ac3..0000000
--- a/framework/private/test/capability_test.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * capability_test.cpp
- *
- * \date Feb 11, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "capability_private.h"
-#include "utils.h"
-#include "attribute.h"
-#include "celix_log.h"
-
-framework_logger_pt logger = (framework_logger_pt) 0x42;
-}
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
-
-TEST_GROUP(capability) {
- void setup(void) {
- }
-
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
-};
-
-TEST(capability, create) {
- capability_pt capability;
- module_pt module = (module_pt) 0x10;
- hash_map_pt directives;
- hash_map_pt attributes;
-
- attribute_pt serviceAttribute = (attribute_pt) 0x01;
- attribute_pt versionAttribute = (attribute_pt) 0x02;
-
- version_pt emptyVersion = (version_pt) 0x10;
- version_pt fromstrVersion = (version_pt) 0x11;
-
- char *value1 = (char *) "target";
- char *value2 = (char *) "1.0.0";
-
- //create with empty version
- directives = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- hashMap_put(attributes, (void*) "service", serviceAttribute);
-
-
- mock().expectOneCall("attribute_getValue")
- .withParameter("attribute", serviceAttribute)
- .withOutputParameterReturning("value", &value1, sizeof(value1))
- .andReturnValue(CELIX_SUCCESS);
- mock().expectOneCall("version_createEmptyVersion")
- .withOutputParameterReturning("version", &emptyVersion, sizeof(emptyVersion))
- .andReturnValue(CELIX_SUCCESS);
-
- capability = NULL;
- capability_create(module, directives, attributes, &capability);
-
- mock().expectOneCall("attribute_destroy")
- .withParameter("attribute", serviceAttribute);
- mock().expectOneCall("version_destroy")
- .withParameter("version", emptyVersion);
-
- capability_destroy(capability);
-
- //create with version from version string
- directives = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
- hashMap_put(attributes, (void*) "service", serviceAttribute);
- hashMap_put(attributes, (void*) "version", versionAttribute);
-
- mock().expectOneCall("attribute_getValue")
- .withParameter("attribute", serviceAttribute)
- .withOutputParameterReturning("value", &value1, sizeof(value1))
- .andReturnValue(CELIX_SUCCESS);
- mock().expectOneCall("attribute_getValue")
- .withParameter("attribute", versionAttribute)
- .withOutputParameterReturning("value", &value2, sizeof(value2))
- .andReturnValue(CELIX_SUCCESS);
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", (char *) "1.0.0")
- .withOutputParameterReturning("version", &fromstrVersion, sizeof(fromstrVersion))
- .andReturnValue(CELIX_SUCCESS);
-
- capability = NULL;
- capability_create(module, directives, attributes, &capability);
-
- mock().expectOneCall("attribute_destroy")
- .withParameter("attribute", serviceAttribute);
- mock().expectOneCall("attribute_destroy")
- .withParameter("attribute", versionAttribute);
- mock().expectOneCall("version_destroy")
- .withParameter("version", fromstrVersion);
-
- capability_destroy(capability);
-}
-
-TEST(capability, getServiceName) {
- capability_pt capability = (capability_pt) malloc(sizeof(*capability));
- char serviceName[] = "service";
- capability->serviceName = serviceName;
-
- const char *actual = NULL;
- capability_getServiceName(capability, &actual);
- STRCMP_EQUAL(serviceName, actual);
-
- free(capability);
-}
-
-TEST(capability, getVersion) {
- capability_pt capability = (capability_pt) malloc(sizeof(*capability));
- version_pt version = (version_pt) 0x10;
- capability->version = version;
-
- version_pt actual = NULL;
- capability_getVersion(capability, &actual);
- POINTERS_EQUAL(version, actual);
-
- free(capability);
-}
-
-TEST(capability, getModule) {
- capability_pt capability = (capability_pt) malloc(sizeof(*capability));
- module_pt module = (module_pt) 0x10;
- capability->module = module;
-
- module_pt actual = NULL;
- capability_getModule(capability, &actual);
- POINTERS_EQUAL(module, actual);
-
- free(capability);
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/celix_errorcodes_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/celix_errorcodes_test.cpp b/framework/private/test/celix_errorcodes_test.cpp
deleted file mode 100644
index 99ed360..0000000
--- a/framework/private/test/celix_errorcodes_test.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * celix_errorcodes_test.cpp
- *
- * \date Oct 16, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "celix_errno.h"
-}
-
-int main(int argc, char** argv) {
- return CommandLineTestRunner::RunAllTests(argc, argv);
-}
-
-TEST_GROUP(celix_errorcodes) {
- void setup(void){
- }
-
- void teardown(void){
- }
-};
-
-TEST(celix_errorcodes, test_entire_file){
- char ret_str[100];
-
- celix_strerror(CELIX_BUNDLE_EXCEPTION, ret_str, 100);
- STRCMP_EQUAL("Bundle exception", ret_str);
-
- celix_strerror(CELIX_INVALID_BUNDLE_CONTEXT, ret_str, 100);
- STRCMP_EQUAL("Invalid bundle context", ret_str);
-
- celix_strerror(CELIX_ILLEGAL_ARGUMENT, ret_str, 100);
- STRCMP_EQUAL("Illegal argument", ret_str);
-
- celix_strerror(CELIX_INVALID_SYNTAX, ret_str, 100);
- STRCMP_EQUAL("Invalid syntax", ret_str);
-
- celix_strerror(CELIX_FRAMEWORK_SHUTDOWN, ret_str, 100);
- STRCMP_EQUAL("Framework shutdown", ret_str);
-
- celix_strerror(CELIX_ILLEGAL_STATE, ret_str, 100);
- STRCMP_EQUAL("Illegal state", ret_str);
-
- celix_strerror(CELIX_FRAMEWORK_EXCEPTION, ret_str, 100);
- STRCMP_EQUAL("Framework exception", ret_str);
-
- celix_strerror(CELIX_FILE_IO_EXCEPTION, ret_str, 100);
- STRCMP_EQUAL("File I/O exception", ret_str);
-
- celix_strerror(CELIX_SERVICE_EXCEPTION, ret_str, 100);
- STRCMP_EQUAL("Service exception", ret_str);
-
- celix_strerror(CELIX_START_ERROR, ret_str, 100);
- STRCMP_EQUAL("Unknown code", ret_str);
-
- //test non celix error code
- STRCMP_EQUAL("Cannot allocate memory",
- celix_strerror(ENOMEM, ret_str, 100));
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/filter_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/filter_test.cpp b/framework/private/test/filter_test.cpp
deleted file mode 100644
index df7255e..0000000
--- a/framework/private/test/filter_test.cpp
+++ /dev/null
@@ -1,574 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "celix_log.h"
-#include "filter.h"
-
-framework_logger_pt logger = (framework_logger_pt) 0x42;
-}
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
-
-static char* my_strdup(const char* s){
- if(s==NULL){
- return NULL;
- }
-
- size_t len = strlen(s);
-
- char *d = (char*) calloc (len + 1,sizeof(char));
-
- if (d == NULL){
- return NULL;
- }
-
- strncpy (d,s,len);
- return d;
-}
-
-//----------------TESTGROUPS----------------
-TEST_GROUP(filter) {
- void setup(void) {
- }
-
- void teardown() {
- mock().clear();
- }
-};
-
-//----------------FILTER TESTS----------------
-TEST(filter, create_destroy){
- char * filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3)))");
- celix_filter_t * get_filter;
-
- get_filter = filter_create(filter_str);
- CHECK(get_filter != NULL);
-
- filter_destroy(get_filter);
-
- //cleanup
- free(filter_str);
-
- mock().checkExpectations();
-}
-
-TEST(filter, create_fail_missing_opening_brackets){
- celix_filter_t * get_filter;
-
- mock().ignoreOtherCalls();
-
- //test missing opening brackets in main filter
- //mock().expectNCalls(2, "framework_log");
- const char *filter_str1 = "&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3))";
- get_filter = filter_create(filter_str1);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test missing opening brackets in AND comparator
- //mock().expectNCalls(3, "framework_log");
- const char *filter_str2 = "(&test_attr1=attr1|(test_attr2=attr2)(test_attr3=attr3))";
- get_filter = filter_create(filter_str2);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test missing opening brackets in AND comparator
- //mock().expectNCalls(4, "framework_log");
- const char *filter_str3 = "(&(test_attr1=attr1)(|test_attr2=attr2(test_attr3=attr3))";
- get_filter = filter_create(filter_str3);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test missing opening brackets in NOT comparator
- //mock().expectNCalls(4, "framework_log");
- const char *filter_str4 = "(&(test_attr1=attr1)(!test_attr2=attr2)";
- get_filter = filter_create(filter_str4);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-}
-
-TEST(filter, create_fail_missing_closing_brackets){
- char * filter_str;
- celix_filter_t * get_filter;
- //test missing closing brackets in substring
- mock().expectNCalls(5, "framework_log");
- filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3");
- get_filter = filter_create(filter_str);
- POINTERS_EQUAL(NULL, get_filter);
- free(filter_str);
- mock().checkExpectations();
-
- //test missing closing brackets in value
- mock().expectNCalls(4, "framework_log");
- filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3>=attr3");
- get_filter = filter_create(filter_str);
- POINTERS_EQUAL(NULL, get_filter);
- free(filter_str);
- mock().checkExpectations();
-}
-
-TEST(filter, create_fail_invalid_closing_brackets){
- char * filter_str;
- celix_filter_t * get_filter;
-
- mock().ignoreOtherCalls();
-
- //test missing closing brackets in substring
- //mock().expectNCalls(6, "framework_log");
- filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=at(tr3)))");
- get_filter = filter_create(filter_str);
- POINTERS_EQUAL(NULL, get_filter);
- free(filter_str);
- mock().checkExpectations();
-
- //test missing closing brackets in value
- //mock().expectNCalls(5, "framework_log");
- filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3>=att(r3)))");
- get_filter = filter_create(filter_str);
- POINTERS_EQUAL(NULL, get_filter);
- free(filter_str);
- mock().checkExpectations();
-}
-
-TEST(filter, create_misc){
- celix_filter_t * get_filter;
-
- mock().ignoreOtherCalls();
-
- //test trailing chars
- //mock().expectOneCall("framework_log");
- const char *filter_str1 = "(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3))) oh no! trailing chars";
- get_filter = filter_create(filter_str1);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test half APPROX operator (should be "~=", instead is "~")
- //mock().expectNCalls(5, "framework_log");
- const char* filter_str2 = "(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3~attr3)))";
- get_filter = filter_create(filter_str2);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test PRESENT operator with trailing chars (should just register as substrings: "*" and "attr3")
- const char *filter_str3 = "(test_attr3=*attr3)";
- get_filter = filter_create(filter_str3);
- CHECK(get_filter != NULL);
- LONGS_EQUAL(CELIX_FILTER_OPERAND_SUBSTRING, get_filter->operand)
- LONGS_EQUAL(2, arrayList_size((array_list_pt) get_filter->children));
- filter_destroy(get_filter);
- mock().checkExpectations();
-
- //test parsing a attribute of 0 length
- //mock().expectNCalls(3, "framework_log");
- const char* filter_str4 = "(>=attr3)";
- get_filter = filter_create(filter_str4);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test parsing a value of 0 length
- //mock().expectOneCall("framework_log");
- const char* filter_str5 = "(test_attr3>=)";
- get_filter = filter_create(filter_str5);
- POINTERS_EQUAL(NULL, get_filter);
- mock().checkExpectations();
-
- //test parsing a value with a escaped closing bracket "\)"
- const char* filter_str6 = "(test_attr3>=strWith\\)inIt)";
- get_filter = filter_create(filter_str6);
- CHECK(get_filter != NULL);
- STRCMP_EQUAL("strWith)inIt", (char*)get_filter->value);
- filter_destroy(get_filter);
- mock().checkExpectations();
-
- //test parsing a substring with a escaped closing bracket "\)"
- const char *filter_str7 = "(test_attr3=strWith\\)inIt)";
- get_filter = filter_create(filter_str7);
- CHECK(get_filter != NULL);
- STRCMP_EQUAL("strWith)inIt", (char*)get_filter->value);
- filter_destroy(get_filter);
- mock().checkExpectations();
-}
-
-TEST(filter, match_comparators){
- char * filter_str;
- celix_filter_t * filter;
- properties_pt props = properties_create();
- char * key = my_strdup("test_attr1");
- char * val = my_strdup("attr1");
- char * key2 = my_strdup("test_attr2");
- char * val2 = my_strdup("attr2");
- properties_set(props, key, val);
- properties_set(props, key2, val2);
-
- //test AND
- filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(!(test_attr3=attr3))))");
- filter = filter_create(filter_str);
- bool result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test AND false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(&(test_attr1=attr1)(test_attr1=attr2))");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //cleanup
- properties_destroy(props);
- filter_destroy(filter);
- free(filter_str);
- free(key);
- free(key2);
- free(val);
- free(val2);
-
- mock().checkExpectations();
-}
-
-TEST(filter, match_operators){
- char * filter_str;
- celix_filter_t * filter;
- properties_pt props = properties_create();
- char * key = my_strdup("test_attr1");
- char * val = my_strdup("attr1");
- char * key2 = my_strdup("test_attr2");
- char * val2 = my_strdup("attr2");
- properties_set(props, key, val);
- properties_set(props, key2, val2);
-
- //test EQUALS
- filter_str = my_strdup("(test_attr1=attr1)");
- filter = filter_create(filter_str);
- bool result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test EQUALS false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1=falseString)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test APPROX TODO: update this test once APPROX is implemented
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1~=attr1)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test APROX false TODO: update this test once APPROX is implemented
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1~=ATTR1)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test PRESENT
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1=*)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test PRESENT false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr3=*)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test LESSEQUAL less
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1<=attr5)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test LESSEQUAL equals
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2<=attr2)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test LESSEQUAL false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2<=attr1)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test GREATEREQUAL greater
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2>=attr1)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test GREATEREQUAL equals
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2>=attr2)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test GREATEREQUAL false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1>=attr5)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test LESS less
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1<attr5)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test LESS equals
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2<attr2)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test LESS false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2<attr1)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test GREATER greater
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2>attr1)");
- filter = filter_create(filter_str);
- result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test GREATER equals
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr2>attr2)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test GREATER false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1>attr5)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //test SUBSTRING equals
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1=attr*)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //test SUBSTRING false
- filter_destroy(filter);
- free(filter_str);
- filter_str = my_strdup("(test_attr1=attr*charsNotPresent)");
- filter = filter_create(filter_str);
- result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //cleanup
- properties_destroy(props);
- filter_destroy(filter);
- free(filter_str);
- free(key);
- free(key2);
- free(val);
- free(val2);
-
- mock().checkExpectations();
-}
-
-TEST(filter, match_recursion){
-
- char * filter_str = my_strdup("(&(test_attr1=attr1)(|(&(test_attr2=attr2)(!(&(test_attr1=attr1)(test_attr3=attr3))))(test_attr3=attr3)))");
- celix_filter_t * filter = filter_create(filter_str);
- properties_pt props = properties_create();
- char * key = my_strdup("test_attr1");
- char * val = my_strdup("attr1");
- char * key2 = my_strdup("test_attr2");
- char * val2 = my_strdup("attr2");
- properties_set(props, key, val);
- properties_set(props, key2, val2);
-
- bool result = false;
- filter_match(filter, props, &result);
- CHECK(result);
-
- //cleanup
- properties_destroy(props);
- filter_destroy(filter);
- free(filter_str);
- free(key);
- free(key2);
- free(val);
- free(val2);
-
- mock().checkExpectations();
-}
-
-TEST(filter, match_false){
- char * filter_str = my_strdup("(&(test_attr1=attr1)(&(test_attr2=attr2)(test_attr3=attr3)))");
- celix_filter_t * filter = filter_create(filter_str);
- properties_pt props = properties_create();
- char * key = my_strdup("test_attr1");
- char * val = my_strdup("attr1");
- char * key2 = my_strdup("test_attr2");
- char * val2 = my_strdup("attr2");
- properties_set(props, key, val);
- properties_set(props, key2, val2);
-
- bool result = true;
- filter_match(filter, props, &result);
- CHECK_FALSE(result);
-
- //cleanup
- properties_destroy(props);
- filter_destroy(filter);
- free(filter_str);
- free(key);
- free(key2);
- free(val);
- free(val2);
-
- mock().checkExpectations();
-}
-
-TEST(filter, match_filter){
- mock().ignoreOtherCalls(); //only log
-
- celix_filter_t *filter = filter_create("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3)))");
- celix_filter_t *compareTo = filter_create("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3)))");
-
- bool result;
- filter_match_filter(filter, compareTo, &result); //equal same order
- CHECK_TRUE(result);
- //cleanup
- filter_destroy(filter);
- filter_destroy(compareTo);
-
- filter = filter_create("(&(test_attr1=attr1)(test_attr2=attr2)(test_attr3=attr3))");
- compareTo = filter_create("(&(test_attr3=attr3)(test_attr2=attr2)(test_attr1=attr1))");
- CHECK(filter != NULL);
- CHECK(compareTo != NULL);
- filter_match_filter(filter, compareTo, &result); //equal not same order
- CHECK_TRUE(result);
- //cleanup
- filter_destroy(filter);
- filter_destroy(compareTo);
-
- filter = filter_create("(&(test_attr1=attr1)(test_attr2=attr2)(test_attr3=attr3))");
- compareTo = filter_create("(&(test_attr1=attr1)(test_attr2=attr2)(test_attr4=attr4))");
- CHECK(filter != NULL);
- CHECK(compareTo != NULL);
- filter_match_filter(filter, compareTo, &result); //almost, but not equal
- CHECK_FALSE(result);
- //cleanup
- filter_destroy(filter);
- filter_destroy(compareTo);
-
- filter_match_filter(NULL, NULL, &result); //both null -> equal
- CHECK_TRUE(result);
-
- filter = filter_create("(attr1=)");
- filter_match_filter(filter, NULL, &result); //one null -> not equal
- CHECK_FALSE(result);
-
- filter_match_filter(NULL, filter, &result); //one null -> not equal
- CHECK_FALSE(result);
-
- filter_destroy(filter);
-}
-
-TEST(filter, getString){
- char * filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=attr3)))");
- celix_filter_t * filter = filter_create(filter_str);
-
- const char * get_str;
- filter_getString(filter, &get_str);
-
- //cleanup
- filter_destroy(filter);
- free(filter_str);
-
- mock().checkExpectations();
-}
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/framework_test.c
----------------------------------------------------------------------
diff --git a/framework/private/test/framework_test.c b/framework/private/test/framework_test.c
deleted file mode 100644
index 7a11e95..0000000
--- a/framework/private/test/framework_test.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * framework_test.c
- *
- * \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <stddef.h>
-
-#include "CUnit/Basic.h"
-#include "framework_private.h"
-
-void test_framework_create(void) {
- struct framework * framework;
- apr_pool_t *memoryPool;
-
- apr_status_t rv = apr_initialize();
- if (rv != APR_SUCCESS) {
- CU_FAIL("Could not initialize APR");
- return;
- }
-
- apr_pool_create(&memoryPool, NULL);
-
- framework_create(&framework, memoryPool, NULL);
-
-
- CU_ASSERT(framework != NULL);
-}
-
-void frameworkTest_startFw() {
- apr_status_t rv = apr_initialize();
- if (rv != APR_SUCCESS) {
- CU_FAIL("Could not initialize APR");
- } else {
- apr_pool_t *memoryPool;
- apr_status_t s = apr_pool_create(&memoryPool, NULL);
- if (s != APR_SUCCESS) {
- CU_FAIL("Could not create memory pool");
- } else {
- framework_pt framework = NULL;
- if (framework_create(&framework, memoryPool, NULL) == CELIX_SUCCESS) {
- if (fw_init(framework) == CELIX_SUCCESS) {
- if (framework_start(framework) == CELIX_SUCCESS) {
- CU_PASS("Framework started");
- framework_stop(framework);
- framework_destroy(framework);
- apr_pool_destroy(memoryPool);
- apr_terminate();
- } else {
- CU_FAIL("Could not create memory pool");
- }
- } else {
- CU_FAIL("Could not create memory pool");
- }
- } else {
- CU_FAIL("Could not create memory pool");
- }
- }
- }
-}
-
-void frameworkTest_installBundle() {
- apr_status_t rv = apr_initialize();
- if (rv != APR_SUCCESS) {
- CU_FAIL("Could not initialize APR");
- } else {
- apr_pool_t *memoryPool;
- apr_status_t s = apr_pool_create(&memoryPool, NULL);
- if (s != APR_SUCCESS) {
- CU_FAIL("Could not create memory pool");
- } else {
- framework_pt framework = NULL;
- if (framework_create(&framework, memoryPool, NULL) == CELIX_SUCCESS) {
- if (fw_init(framework) == CELIX_SUCCESS) {
- if (framework_start(framework) == CELIX_SUCCESS) {
-
- // fw_installBundle(); // Needs a fake bundle..
-
- framework_stop(framework);
- framework_destroy(framework);
- apr_pool_destroy(memoryPool);
- apr_terminate();
- } else {
- CU_FAIL("Could not create memory pool");
- }
- } else {
- CU_FAIL("Could not create memory pool");
- }
- } else {
- CU_FAIL("Could not create memory pool");
- }
- }
- }
-}
-
-
-int main (int argc, char** argv) {
- CU_pSuite pSuite = NULL;
-
- /* initialize the CUnit test registry */
- if (CUE_SUCCESS != CU_initialize_registry())
- return CU_get_error();
-
- /* add a suite to the registry */
- pSuite = CU_add_suite("Framework", NULL, NULL);
- if (NULL == pSuite) {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* add the tests to the suite */
- if (
- NULL == CU_add_test(pSuite, "Framework Creation Test", test_framework_create)
- || NULL == CU_add_test(pSuite, "Start/Stop test", frameworkTest_startFw)
- )
- {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* Run all tests using the CUnit Basic interface */
- CU_basic_set_mode(CU_BRM_VERBOSE);
- CU_basic_run_tests();
- CU_cleanup_registry();
- return CU_get_error();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/framework_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/framework_test.cpp b/framework/private/test/framework_test.cpp
deleted file mode 100644
index 3cad49c..0000000
--- a/framework/private/test/framework_test.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * framework_test.cpp
- *
- * \date Sep 28, 2015
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "framework.h"
-#include "framework_private.h"
-}
-
-int main(int argc, char** argv) {
- return CommandLineTestRunner::RUN_ALL_TESTS(argc, argv);
-}
-
-TEST_GROUP(framework) {
- properties_pt properties;
-
- void setup(void) {
- properties = properties_create();
- }
-
- void teardown() {
- properties_destroy(properties);
- }
-};
-
-TEST(framework, create){
- //framework_pt framework = NULL;
-
- //mock().expectOneCall("bundle_create").ignoreOtherParameters();
- //mock().ignoreOtherCalls();
-
- //framework_create(&framework, properties);
-
-
- //CHECK(framework != NULL);
-
- mock().checkExpectations();
- mock().clear();
-}
-
-/*TEST(framework, startFw){
- framework_pt framework = NULL;
-
- mock().expectOneCall("bundle_create");
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- LONGS_EQUAL(CELIX_SUCCESS,framework_create(&framework, properties));
-
- LONGS_EQUAL(CELIX_SUCCESS,fw_init(framework));
-
- LONGS_EQUAL(CELIX_SUCCESS,framework_start(framework));
-
- framework_stop(framework);
- framework_destroy(framework);
-
-}
-
-TEST(framework, installBundle){
- framework_pt framework = NULL;
-
- mock().expectOneCall("bundle_create");
- mock().expectOneCall("framework_logCode")
- .withParameter("code", CELIX_ILLEGAL_ARGUMENT);
-
- LONGS_EQUAL(CELIX_SUCCESS, framework_create(&framework, properties));
-
- LONGS_EQUAL(CELIX_SUCCESS,fw_init(framework));
-
- LONGS_EQUAL(CELIX_SUCCESS,framework_start(framework));
-
- // fw_installBundle(); // Needs a fake bundle..
-
- framework_stop(framework);
- framework_destroy(framework);
-
-}*/
-
-
-
-
-
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/manifest_parser_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/manifest_parser_test.cpp b/framework/private/test/manifest_parser_test.cpp
deleted file mode 100644
index d3fdbbf..0000000
--- a/framework/private/test/manifest_parser_test.cpp
+++ /dev/null
@@ -1,254 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * manifest_parser_test.cpp
- *
- * \date Feb 11, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "capability_private.h"
-#include "requirement_private.h"
-#include "constants.h"
-#include "manifest_parser.h"
-#include "attribute.h"
-#include "celix_log.h"
-
-framework_logger_pt logger = (framework_logger_pt) 0x42;
-}
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
-
-static char* my_strdup(const char* s) {
- if (s == NULL) {
- return NULL;
- }
-
- size_t len = strlen(s);
-
- char *d = (char*) calloc(len + 1, sizeof(char));
-
- if (d == NULL) {
- return NULL;
- }
-
- strncpy(d, s, len);
- return d;
-}
-
-TEST_GROUP(manifest_parser) {
- void setup(void) {
- }
-
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
-};
-
-TEST(manifest_parser, create){
- module_pt owner = (module_pt) 0x01;
- manifest_pt manifest = (manifest_pt) 0x02;
- manifest_parser_pt parser;
- char * service_name_key = my_strdup("service");
- char * service_version_key = my_strdup("version");
-
- //get generic bundle data
- char * version_str = my_strdup("1.2.3");
- char * bundle_name = my_strdup("Test_Bundle");
- version_pt version = (version_pt) 0x03;
-
- mock().expectOneCall("manifest_getValue")
- .withParameter("name", OSGI_FRAMEWORK_BUNDLE_VERSION)
- .andReturnValue(version_str);
-
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", version_str)
- .withOutputParameterReturning("version", &version, sizeof(version));
-
- mock().expectOneCall("manifest_getValue")
- .withParameter("name", OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME)
- .andReturnValue(bundle_name);
-
- //create capabilities
- char * export_header = my_strdup("export_service_name;version=\"4.5.6\",export_service_name2;version=\"6.5.4\"");
- char * cap_name = my_strdup("export_service_name");
- char * cap_name2 = my_strdup("export_service_name2");
- char * cap_version_str = my_strdup("4.5.6");
- char * cap_version_str2 = my_strdup("6.5.4");
- version_pt cap_version = (version_pt) 0x0A;
- version_pt cap_version2 = (version_pt) 0x0B;
-
- mock().expectOneCall("manifest_getValue")
- .withParameter("name", OSGI_FRAMEWORK_EXPORT_LIBRARY)
- .andReturnValue(export_header);
-
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", cap_version_str)
- .withOutputParameterReturning("version", &cap_version, sizeof(cap_version));
-
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", cap_version_str2)
- .withOutputParameterReturning("version", &cap_version2, sizeof(cap_version2));
-
- //create requirements
- char * import_header = my_strdup("import_service_name;version=\"[7.8,9)\",import_service_name2;version=\"[9.8,7)\"");
- char * req_name = my_strdup("import_service_name");
- char * req_name2 = my_strdup("import_service_name2");
- char * req_version_str = my_strdup("[7.8,9)");
- char * req_version_str2 = my_strdup("[9.8,7)");
- version_range_pt req_version_range = (version_range_pt) 0x12;
- version_range_pt req_version_range2 = (version_range_pt) 0x13;
-
- mock().expectOneCall("manifest_getValue")
- .withParameter("name", OSGI_FRAMEWORK_IMPORT_LIBRARY)
- .andReturnValue(import_header);
-
- mock().expectOneCall("versionRange_parse")
- .withParameter("rangeStr", req_version_str)
- .withOutputParameterReturning("range", &req_version_range, sizeof(req_version_range));
-
- mock().expectOneCall("versionRange_parse")
- .withParameter("rangeStr", req_version_str2)
- .withOutputParameterReturning("range", &req_version_range2, sizeof(req_version_range2));
-
-
- //actual call to create
- manifestParser_create(owner, manifest, &parser);
-
- //test getters
- capability_pt get_cap;
- requirement_pt get_req;
- version_pt version_clone = (version_pt) 0x14;
- version_pt get_version;
- linked_list_pt get_caps;
- linked_list_pt get_reqs;
- char* get_bundle_name;
- celix_status_t status;
-
- mock().expectOneCall("version_clone")
- .withParameter("version", version)
- .withOutputParameterReturning("clone", &version_clone, sizeof(version_clone));
-
- status = manifestParser_getBundleVersion(parser, &get_version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(version_clone, get_version);
-
- status = manifestParser_getCapabilities(parser, &get_caps);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- LONGS_EQUAL(2, linkedList_size(get_caps));
- //check for both capabilities, in no specific order
- get_cap = (capability_pt)linkedList_get(get_caps, 0);
- if (strcmp(get_cap->serviceName, cap_name) == 0){
- POINTERS_EQUAL(cap_version, get_cap->version);
- get_cap = (capability_pt)linkedList_get(get_caps, 1);
- STRCMP_EQUAL(cap_name2, get_cap->serviceName);
- POINTERS_EQUAL(cap_version2, get_cap->version);
- } else {
- STRCMP_EQUAL(cap_name2, get_cap->serviceName);
- POINTERS_EQUAL(cap_version2, get_cap->version);
- get_cap = (capability_pt)linkedList_get(get_caps, 1);
- STRCMP_EQUAL(cap_name, get_cap->serviceName);
- POINTERS_EQUAL(cap_version, get_cap->serviceName);
- }
-
- status = manifestParser_getRequirements(parser, &get_reqs);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- LONGS_EQUAL(2, linkedList_size(get_reqs));
- //check for both requirements, in no specific order
- get_req = (requirement_pt)linkedList_get(get_reqs, 0);
- if (strcmp(get_req->targetName, req_name) == 0){
- POINTERS_EQUAL(req_version_range, get_req->versionRange);
- get_req = (requirement_pt)linkedList_get(get_reqs, 1);
- STRCMP_EQUAL(req_name2, get_req->targetName);
- POINTERS_EQUAL(req_version_range2, get_req->versionRange);
- } else {
- STRCMP_EQUAL(req_name2, get_req->targetName);
- POINTERS_EQUAL(req_version_range2, get_req->versionRange);
- get_req = (requirement_pt)linkedList_get(get_reqs, 1);
- STRCMP_EQUAL(req_name, get_req->targetName);
- POINTERS_EQUAL(req_version_range, get_req->versionRange);
- }
-
-
- status = manifestParser_getAndDuplicateSymbolicName(parser, &get_bundle_name);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- STRCMP_EQUAL(bundle_name, get_bundle_name);
-
-
- //cleanup
- mock().expectOneCall("version_destroy")
- .withParameter("version", version);
-
- manifestParser_destroy(parser);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", cap_version);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", cap_version2);
-
- mock().expectOneCall("versionRange_destroy")
- .withParameter("range", req_version_range);
-
- mock().expectOneCall("versionRange_destroy")
- .withParameter("range", req_version_range2);
-
- capability_destroy((capability_pt) linkedList_get(get_caps, 0));
- capability_destroy((capability_pt) linkedList_get(get_caps, 1));
-
- requirement_destroy((requirement_pt) linkedList_get(get_reqs, 0));
- requirement_destroy((requirement_pt) linkedList_get(get_reqs, 1));
-
- linkedList_destroy(get_caps);
- linkedList_destroy(get_reqs);
-
- free(service_name_key);
- free(service_version_key);
-
- free(version_str);
- free(bundle_name);
-
- free(export_header);
- free(cap_name);
- free(cap_name2);
- free(cap_version_str);
- free(cap_version_str2);
-
- free(import_header);
- free(req_name);
- free(req_name2);
- free(req_version_str);
- free(req_version_str2);
-
- free(get_bundle_name);
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/3bce889b/framework/private/test/manifest_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/manifest_test.cpp b/framework/private/test/manifest_test.cpp
deleted file mode 100644
index 5138fa5..0000000
--- a/framework/private/test/manifest_test.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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.
- */
-/*
- * manifest_test.cpp
- *
- * \date Feb 11, 2013
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "CppUTest/TestHarness.h"
-#include "CppUTest/TestHarness_c.h"
-#include "CppUTest/CommandLineTestRunner.h"
-#include "CppUTestExt/MockSupport.h"
-
-extern "C" {
-#include "manifest.h"
-#include "hash_map.h"
-#include "celix_log.h"
-
-framework_logger_pt logger = (framework_logger_pt) 0x42;
-}
-
-int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
-}
-
-TEST_GROUP(manifest) {
- void setup(void) {
- }
-
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
-};
-
-TEST(manifest, dead_code){
- manifest_pt empty = NULL;
- manifest_clear(empty);
- manifest_write(empty, (char*)"filename");
-}
-
-TEST(manifest, createFromFile) {
- char manifestFile[] = "resources-test/manifest.txt";
- manifest_pt manifest = NULL;
-// properties_pt properties = properties_create();
- properties_pt properties = (properties_pt) 0x40;
- void *ov = (void *) 0x00;
-
- mock()
- .expectOneCall("properties_create")
- .andReturnValue(properties);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Bundle-SymbolicName")
- .withParameter("value", "client")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Bundle-Version")
- .withParameter("value", "1.0.0")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "library")
- .withParameter("value", "client")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Import-Service")
- .withParameter("value", "server")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_destroy")
- .withParameter("properties", properties);
-
- manifest_createFromFile(manifestFile, &manifest);
- manifest_destroy(manifest);
-}
-
-TEST(manifest, createFromFileWithSections) {
- char manifestFile[] = "resources-test/manifest_sections.txt";
- manifest_pt manifest = NULL;
- //properties_pt properties = properties_create();
- properties_pt properties = (properties_pt) 0x01;
- properties_pt properties2 = (properties_pt) 0x02;
- properties_pt properties3 = (properties_pt) 0x03;
- properties_pt properties4 = (properties_pt) 0x04;
- void *ov = (void *) 0x00;
-
- mock()
- .expectOneCall("properties_create")
- .andReturnValue(properties);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Bundle-SymbolicName")
- .withParameter("value", "client")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Bundle-Version")
- .withParameter("value", "1.0.0")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "library")
- .withParameter("value", "client")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties)
- .withParameter("key", "Import-Service")
- .withParameter("value", "server")
- .andReturnValue(ov);
-
- mock()
- .expectOneCall("properties_create")
- .andReturnValue(properties2);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties2)
- .withParameter("key", "aa")
- .withParameter("value", "1")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties2)
- .withParameter("key", "ab")
- .withParameter("value", "2")
- .andReturnValue(ov);
-
- mock()
- .expectOneCall("properties_create")
- .andReturnValue(properties3);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties3)
- .withParameter("key", "ba")
- .withParameter("value", "3")
- .andReturnValue(ov);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties3)
- .withParameter("key", "bb")
- .withParameter("value", "4")
- .andReturnValue(ov);
-
- mock()
- .expectOneCall("properties_create")
- .andReturnValue(properties4);
- mock()
- .expectOneCall("properties_set")
- .withParameter("properties", properties4)
- .withParameter("key", "white space")
- .withParameter("value", "5")
- .andReturnValue(ov);
-
- manifest_createFromFile(manifestFile, &manifest);
-
- mock()
- .expectOneCall("properties_get")
- .withParameter("properties", properties)
- .withParameter("key", "Bundle-SymbolicName")
- .andReturnValue("bsn");
-
- properties_pt main = manifest_getMainAttributes(manifest);
- POINTERS_EQUAL(properties, main);
-
- const char *name = manifest_getValue(manifest, "Bundle-SymbolicName");
- STRCMP_EQUAL("bsn", name);
-
- hash_map_pt map = NULL;
- manifest_getEntries(manifest, &map);
- LONGS_EQUAL(3, hashMap_size(map));
-
- properties_pt actual = (properties_pt) hashMap_get(map, (void *) "a");
- POINTERS_EQUAL(properties2, actual);
-
- actual = (properties_pt) hashMap_get(map, (void *) "b");
- POINTERS_EQUAL(properties3, actual);
-
- mock()
- .expectOneCall("properties_destroy")
- .withParameter("properties", properties);
-
- manifest_destroy(manifest);
-}
-