You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by rl...@apache.org on 2019/07/17 17:33:41 UTC
[celix] 01/03: Updated utils to use celix_properties_t* instead of
properties_pt
This is an automated email from the ASF dual-hosted git repository.
rlenferink pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git
commit eb199825e4be4cf01a2963370c28b200a732303c
Author: Roy Lenferink <le...@gmail.com>
AuthorDate: Wed Jul 17 18:36:16 2019 +0200
Updated utils to use celix_properties_t* instead of properties_pt
Updated license headers and formatting as well
---
libs/utils/include/array_list.h | 32 +-
libs/utils/include/celix_array_list.h | 28 +-
libs/utils/include/celix_errno.h | 34 +-
libs/utils/include/celix_filter.h | 28 +-
libs/utils/include/celix_properties.h | 28 +-
libs/utils/include/celix_threads.h | 40 +-
libs/utils/include/celix_utils_api.h | 28 +-
libs/utils/include/celixbool.h | 34 +-
libs/utils/include/exports.h | 32 +-
libs/utils/include/filter.h | 28 +-
libs/utils/include/hash_map.h | 46 +-
libs/utils/include/ip_utils.h | 4 +-
libs/utils/include/linked_list.h | 32 +-
libs/utils/include/linked_list_iterator.h | 32 +-
libs/utils/include/properties.h | 32 +-
libs/utils/include/utils.h | 32 +-
libs/utils/include/version.h | 74 +-
libs/utils/include/version_range.h | 52 +-
libs/utils/private/test/array_list_test.cpp | 823 ++++-----
libs/utils/private/test/celix_threads_test.cpp | 587 ++++---
libs/utils/private/test/filter_test.cpp | 4 +-
libs/utils/private/test/hash_map_test.cpp | 2247 ++++++++++++------------
libs/utils/private/test/ip_utils_test.cpp | 14 +-
libs/utils/private/test/linked_list_test.cpp | 1071 +++++------
libs/utils/private/test/properties_test.cpp | 335 ++--
libs/utils/private/test/thread_pool_test.cpp | 125 +-
libs/utils/private/test/utils_test.cpp | 451 ++---
libs/utils/private/test/version_range_test.cpp | 368 ++--
libs/utils/private/test/version_test.cpp | 514 +++---
libs/utils/src/array_list.c | 659 +++----
libs/utils/src/array_list_private.h | 52 +-
libs/utils/src/celix_threads.c | 136 +-
libs/utils/src/filter.c | 942 +++++-----
libs/utils/src/hash_map.c | 785 ++++-----
libs/utils/src/hash_map_private.h | 64 +-
libs/utils/src/ip_utils.c | 4 +-
libs/utils/src/linked_list.c | 281 +--
libs/utils/src/linked_list_iterator.c | 199 +--
libs/utils/src/linked_list_private.h | 44 +-
libs/utils/src/properties.c | 638 +++----
libs/utils/src/utils.c | 187 +-
libs/utils/src/version.c | 396 ++---
libs/utils/src/version_private.h | 37 +-
libs/utils/src/version_range.c | 278 +--
libs/utils/src/version_range_private.h | 37 +-
45 files changed, 5951 insertions(+), 5943 deletions(-)
diff --git a/libs/utils/include/array_list.h b/libs/utils/include/array_list.h
index 9262984..a0c8bd4 100644
--- a/libs/utils/include/array_list.h
+++ b/libs/utils/include/array_list.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list.h
*
* \date Aug 4, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef ARRAY_LIST_H_
diff --git a/libs/utils/include/celix_array_list.h b/libs/utils/include/celix_array_list.h
index 4bb3e7b..7184bfd 100644
--- a/libs/utils/include/celix_array_list.h
+++ b/libs/utils/include/celix_array_list.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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 "celixbool.h"
diff --git a/libs/utils/include/celix_errno.h b/libs/utils/include/celix_errno.h
index b51540b..0636d99 100644
--- a/libs/utils/include/celix_errno.h
+++ b/libs/utils/include/celix_errno.h
@@ -1,27 +1,27 @@
-/*
- *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
+/**
+ * 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
+ * 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.
+ * 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_errno.h
*
* \date Feb 15, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
/*!
\file
diff --git a/libs/utils/include/celix_filter.h b/libs/utils/include/celix_filter.h
index 4d0d7fa..a6a9e15 100644
--- a/libs/utils/include/celix_filter.h
+++ b/libs/utils/include/celix_filter.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
#ifndef CELIX_FILTER_H_
diff --git a/libs/utils/include/celix_properties.h b/libs/utils/include/celix_properties.h
index fbc59ab..b86c297 100644
--- a/libs/utils/include/celix_properties.h
+++ b/libs/utils/include/celix_properties.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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 <stdio.h>
diff --git a/libs/utils/include/celix_threads.h b/libs/utils/include/celix_threads.h
index a4bc54c..af33a99 100644
--- a/libs/utils/include/celix_threads.h
+++ b/libs/utils/include/celix_threads.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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_threads.h
@@ -37,8 +37,8 @@ extern "C" {
#endif
struct celix_thread {
- bool threadInitialized;
- pthread_t thread;
+ bool threadInitialized;
+ pthread_t thread;
};
typedef pthread_once_t celix_thread_once_t;
@@ -79,10 +79,10 @@ typedef pthread_mutexattr_t celix_thread_mutexattr_t;
//MUTEX TYPES
enum {
- CELIX_THREAD_MUTEX_NORMAL,
- CELIX_THREAD_MUTEX_RECURSIVE,
- CELIX_THREAD_MUTEX_ERRORCHECK,
- CELIX_THREAD_MUTEX_DEFAULT
+ CELIX_THREAD_MUTEX_NORMAL,
+ CELIX_THREAD_MUTEX_RECURSIVE,
+ CELIX_THREAD_MUTEX_ERRORCHECK,
+ CELIX_THREAD_MUTEX_DEFAULT
};
diff --git a/libs/utils/include/celix_utils_api.h b/libs/utils/include/celix_utils_api.h
index 48324c3..afe9ba7 100644
--- a/libs/utils/include/celix_utils_api.h
+++ b/libs/utils/include/celix_utils_api.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
#ifndef CELIX_CELIX_UTILS_API_H_
diff --git a/libs/utils/include/celixbool.h b/libs/utils/include/celixbool.h
index 526392b..50fa7c6 100644
--- a/libs/utils/include/celixbool.h
+++ b/libs/utils/include/celixbool.h
@@ -1,27 +1,27 @@
-/*
- *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
+/**
+ * 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
+ * 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.
+ * 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.
*/
/*
* celixbool.h
*
* \date Jun 16, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef CELIXBOOL_H_
diff --git a/libs/utils/include/exports.h b/libs/utils/include/exports.h
index b128c88..23b6146 100644
--- a/libs/utils/include/exports.h
+++ b/libs/utils/include/exports.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* exports.h
*
* \date Jun 16, 2011
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef EXPORTS_H_
diff --git a/libs/utils/include/filter.h b/libs/utils/include/filter.h
index 105925c..b972c11 100644
--- a/libs/utils/include/filter.h
+++ b/libs/utils/include/filter.h
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
#ifndef FILTER_H_
diff --git a/libs/utils/include/hash_map.h b/libs/utils/include/hash_map.h
index d9d1b66..ec030c1 100644
--- a/libs/utils/include/hash_map.h
+++ b/libs/utils/include/hash_map.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* hash_map.h
*
* \date Jul 21, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef HASH_MAP_H_
@@ -41,11 +41,11 @@ typedef struct hashMap* hash_map_pt;
typedef struct hashMap hash_map_t;
struct hashMapIterator {
- hash_map_pt map;
- hash_map_entry_pt next;
- hash_map_entry_pt current;
- int expectedModCount;
- int index;
+ hash_map_pt map;
+ hash_map_entry_pt next;
+ hash_map_entry_pt current;
+ int expectedModCount;
+ int index;
};
typedef struct hashMapIterator hash_map_iterator_t;
@@ -56,8 +56,8 @@ typedef struct hashMapValues *hash_map_values_pt;
typedef struct hashMapEntrySet *hash_map_entry_set_pt;
UTILS_EXPORT hash_map_pt hashMap_create(unsigned int (*keyHash)(const void *), unsigned int (*valueHash)(const void *),
- int (*keyEquals)(const void *, const void *),
- int (*valueEquals)(const void *, const void *));
+ int (*keyEquals)(const void *, const void *),
+ int (*valueEquals)(const void *, const void *));
UTILS_EXPORT void hashMap_destroy(hash_map_pt map, bool freeKeys, bool freeValues);
diff --git a/libs/utils/include/ip_utils.h b/libs/utils/include/ip_utils.h
index d95a14a..8f8fe5c 100644
--- a/libs/utils/include/ip_utils.h
+++ b/libs/utils/include/ip_utils.h
@@ -20,8 +20,8 @@
* ip_utils.h
*
* \date Jun 24, 2019
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef IP_UTILS_H_
diff --git a/libs/utils/include/linked_list.h b/libs/utils/include/linked_list.h
index 04c1162..e5d449e 100644
--- a/libs/utils/include/linked_list.h
+++ b/libs/utils/include/linked_list.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* linked_list.h
*
* \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef LINKED_LIST_H_
diff --git a/libs/utils/include/linked_list_iterator.h b/libs/utils/include/linked_list_iterator.h
index f765d5d..393d4cc 100644
--- a/libs/utils/include/linked_list_iterator.h
+++ b/libs/utils/include/linked_list_iterator.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* linked_list_iterator.h
*
* \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef LINKED_LIST_ITERATOR_H_
diff --git a/libs/utils/include/properties.h b/libs/utils/include/properties.h
index f0070bd..c295eb5 100644
--- a/libs/utils/include/properties.h
+++ b/libs/utils/include/properties.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* properties.h
*
* \date Apr 27, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef PROPERTIES_H_
diff --git a/libs/utils/include/utils.h b/libs/utils/include/utils.h
index 11a200f..78d025d 100644
--- a/libs/utils/include/utils.h
+++ b/libs/utils/include/utils.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* utils.h
*
* \date Jul 27, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef UTILS_H_
diff --git a/libs/utils/include/version.h b/libs/utils/include/version.h
index 88e146a..50a91f7 100644
--- a/libs/utils/include/version.h
+++ b/libs/utils/include/version.h
@@ -1,27 +1,27 @@
/**
- *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.
+ * 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.
*/
/*
* version.h
*
* \date Jul 12, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef VERSION_H_
@@ -50,10 +50,10 @@ typedef struct version *version_pt;
* the empty string.
* @param version The created version_pt
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
- * or the qualifier string is invalid.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
+ * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
+ * or the qualifier string is invalid.
*/
celix_status_t version_createVersion(int major, int minor, int micro, char *qualifier, version_pt *version);
@@ -65,10 +65,10 @@ celix_status_t version_destroy(version_pt version);
* @param version The version to clone
* @param clone The cloned version
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
- * or the qualifier string is invalid.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
+ * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative
+ * or the qualifier string is invalid.
*/
celix_status_t version_clone(version_pt version, version_pt *clone);
@@ -93,10 +93,10 @@ celix_status_t version_clone(version_pt version, version_pt *clone);
* @param versionStr String representation of the version identifier.
* @param version The created version_pt
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
+ * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
+ * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
*/
celix_status_t version_createVersionFromString(const char *versionStr, version_pt *version);
@@ -105,10 +105,10 @@ celix_status_t version_createVersionFromString(const char *versionStr, version_p
*
* @param version The created version_pt
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>version</code> failed.
+ * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
+ * the qualifier string is invalid or <code>versionStr</code> is improperly formatted.
*/
celix_status_t version_createEmptyVersion(version_pt *version);
@@ -143,7 +143,7 @@ celix_status_t version_getQualifier(version_pt version, const char **qualifier);
* @param result A negative integer, zero, or a positive integer if <code>version</code> is
* less than, equal to, or greater than the <code>compare</code>.
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_SUCCESS when no errors are encountered.
*/
celix_status_t version_compareTo(version_pt version, version_pt compare, int *result);
@@ -159,7 +159,7 @@ celix_status_t version_compareTo(version_pt version, version_pt compare, int *re
* @param version The <code>version_pt</code> to get the string representation from.
* @param string Pointer to the string (char *) in which the result will be placed.
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_SUCCESS when no errors are encountered.
*/
celix_status_t version_toString(version_pt version, char **string);
@@ -175,7 +175,7 @@ celix_status_t version_toString(version_pt version, char **string);
* @param version The reference provider <code>version_pt</code> .
* @param Boolean indicating if the versions are compatible
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_SUCCESS when no errors are encountered.
*/
celix_status_t version_isCompatible(version_pt user, version_pt provider, bool *isCompatible);
diff --git a/libs/utils/include/version_range.h b/libs/utils/include/version_range.h
index b661cd3..e93d52b 100644
--- a/libs/utils/include/version_range.h
+++ b/libs/utils/include/version_range.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* version_range.h
*
* \date Jul 12, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef VERSION_RANGE_H_
@@ -54,8 +54,8 @@ typedef struct versionRange *version_range_pt;
* @param isHighInclusive True if upper bound should be included in the range
* @param versionRange The created range
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
*/
celix_status_t
versionRange_createVersionRange(version_pt low, bool isLowInclusive, version_pt high, bool isHighInclusive,
@@ -63,12 +63,12 @@ versionRange_createVersionRange(version_pt low, bool isLowInclusive, version_pt
/**
* Creates an infinite version range using ::version_createEmptyVersion for the low version,
- * NULL for the high version and high and low inclusive set to true.
+ * NULL for the high version and high and low inclusive set to true.
*
* @param range The created range
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>range</code> failed.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>range</code> failed.
*/
celix_status_t versionRange_createInfiniteVersionRange(version_range_pt *range);
@@ -81,7 +81,7 @@ celix_status_t versionRange_destroy(version_range_pt range);
* @param version The version to check.
* @param inRange True if the specified version is included in this version range, false otherwise.
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_SUCCESS when no errors are encountered.
*/
celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version, bool *inRange);
@@ -146,10 +146,10 @@ celix_status_t versionRange_getHighVersion(version_range_pt versionRange, versio
* @param rangeStr String representation of the version range.
* @param range The created version_range_pt.
* @return Status code indication failure or success:
- * - CELIX_SUCCESS when no errors are encountered.
- * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
- * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
- * the qualifier string is invalid or <code>versionStr</code> is impropertly formatted.
+ * - CELIX_SUCCESS when no errors are encountered.
+ * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed.
+ * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative,
+ * the qualifier string is invalid or <code>versionStr</code> is impropertly formatted.
*/
celix_status_t versionRange_parse(const char *rangeStr, version_range_pt *range);
diff --git a/libs/utils/private/test/array_list_test.cpp b/libs/utils/private/test/array_list_test.cpp
index 4c908e3..8a4a965 100644
--- a/libs/utils/private/test/array_list_test.cpp
+++ b/libs/utils/private/test/array_list_test.cpp
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list_test.cpp
*
- * \date Sep 15, 2015
- * \author Menno van der Graaf & Alexander
- * \copyright Apache License, Version 2.0
+ * \date Sep 15, 2015
+ * \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 <string.h>
@@ -40,544 +41,544 @@ extern "C"
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s){
- char *d = (char*) malloc (strlen (s) + 1);
- if (d == NULL) return NULL;
- strcpy (d,s);
- return d;
+ char *d = (char*) malloc (strlen (s) + 1);
+ if (d == NULL) return NULL;
+ strcpy (d,s);
+ return d;
}
//----------------------TESTS GROUP DEFINES----------------------
TEST_GROUP(array_list) {
- array_list_pt list;
-
- void setup(){
- arrayList_create(&list);
- }
- void teardown() {
- arrayList_destroy(list);
- }
+ array_list_pt list;
+
+ void setup(){
+ arrayList_create(&list);
+ }
+ void teardown() {
+ arrayList_destroy(list);
+ }
};
TEST_GROUP(array_list_iterator) {
- array_list_pt list;
-
- void setup(){
- arrayList_create(&list);
- }
- void teardown() {
- arrayList_destroy(list);
- }
+ array_list_pt list;
+
+ void setup(){
+ arrayList_create(&list);
+ }
+ void teardown() {
+ arrayList_destroy(list);
+ }
};
//----------------------ARRAY LIST TESTS----------------------
TEST(array_list, create) {
- CHECK_C(list != NULL);
- LONGS_EQUAL(0, list->size);
+ CHECK_C(list != NULL);
+ LONGS_EQUAL(0, list->size);
}
TEST(array_list, trimToSize) {
- char * entry = my_strdup("entry");
- arrayList_clear(list);
+ char * entry = my_strdup("entry");
+ arrayList_clear(list);
- arrayList_add(list, entry);
- LONGS_EQUAL(1, list->size);
- LONGS_EQUAL(10, list->capacity);
+ arrayList_add(list, entry);
+ LONGS_EQUAL(1, list->size);
+ LONGS_EQUAL(10, list->capacity);
- arrayList_trimToSize(list);
- LONGS_EQUAL(1, list->size);
- LONGS_EQUAL(1, list->capacity);
+ arrayList_trimToSize(list);
+ LONGS_EQUAL(1, list->size);
+ LONGS_EQUAL(1, list->capacity);
- free(entry);
+ free(entry);
}
TEST(array_list, ensureCapacity) {
- int i;
- arrayList_clear(list);
-
- LONGS_EQUAL(10, list->capacity);
- LONGS_EQUAL(0, list->size);
-
- for (i = 0; i < 100; i++) {
- char * entry = my_strdup("entry");
- arrayList_add(list, entry);
- }
- LONGS_EQUAL(133, list->capacity);
- LONGS_EQUAL(100, list->size);
-
- for (i = 99; i >= 0; i--) {
- free(arrayList_remove(list, i));
- }
+ int i;
+ arrayList_clear(list);
+
+ LONGS_EQUAL(10, list->capacity);
+ LONGS_EQUAL(0, list->size);
+
+ for (i = 0; i < 100; i++) {
+ char * entry = my_strdup("entry");
+ arrayList_add(list, entry);
+ }
+ LONGS_EQUAL(133, list->capacity);
+ LONGS_EQUAL(100, list->size);
+
+ for (i = 99; i >= 0; i--) {
+ free(arrayList_remove(list, i));
+ }
}
TEST(array_list, clone) {
- int i;
- arrayList_clear(list);
-
- LONGS_EQUAL(10, list->capacity);
- LONGS_EQUAL(0, list->size);
-
- for (i = 0; i < 12; i++) {
- bool added;
- char entry[11];
- sprintf(entry, "|%s|%d|", "entry", i);
- added = arrayList_add(list, my_strdup(entry));
- CHECK(added);
- }
- LONGS_EQUAL(16, list->capacity);
- LONGS_EQUAL(12, list->size);
-
- array_list_pt clone = NULL;
- clone = arrayList_clone(list);
-
- LONGS_EQUAL(16, clone->capacity);
- LONGS_EQUAL(12, clone->size);
-
- unsigned int j;
- for (j = 0; j < 12; j++) {
- void *entry = NULL;
- char entrys[11];
- sprintf(entrys, "|%s|%d|", "entry", j);
-
- entry = arrayList_get(clone, j);
- STRCMP_EQUAL((char *) entry, entrys);
- }
-
- for (i = 11; i >= 0; i--) {
- free(arrayList_remove(list, i));
- }
- arrayList_destroy(clone);
+ int i;
+ arrayList_clear(list);
+
+ LONGS_EQUAL(10, list->capacity);
+ LONGS_EQUAL(0, list->size);
+
+ for (i = 0; i < 12; i++) {
+ bool added;
+ char entry[11];
+ sprintf(entry, "|%s|%d|", "entry", i);
+ added = arrayList_add(list, my_strdup(entry));
+ CHECK(added);
+ }
+ LONGS_EQUAL(16, list->capacity);
+ LONGS_EQUAL(12, list->size);
+
+ array_list_pt clone = NULL;
+ clone = arrayList_clone(list);
+
+ LONGS_EQUAL(16, clone->capacity);
+ LONGS_EQUAL(12, clone->size);
+
+ unsigned int j;
+ for (j = 0; j < 12; j++) {
+ void *entry = NULL;
+ char entrys[11];
+ sprintf(entrys, "|%s|%d|", "entry", j);
+
+ entry = arrayList_get(clone, j);
+ STRCMP_EQUAL((char *) entry, entrys);
+ }
+
+ for (i = 11; i >= 0; i--) {
+ free(arrayList_remove(list, i));
+ }
+ arrayList_destroy(clone);
}
TEST(array_list, size){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry");
- char * entry3 = my_strdup("entry");
- arrayList_clear(list);
- LONGS_EQUAL(0, list->size);
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry");
+ char * entry3 = my_strdup("entry");
+ arrayList_clear(list);
+ LONGS_EQUAL(0, list->size);
- arrayList_add(list, entry);
- LONGS_EQUAL(1, list->size);
+ arrayList_add(list, entry);
+ LONGS_EQUAL(1, list->size);
- arrayList_add(list, entry2);
- LONGS_EQUAL(2, list->size);
+ arrayList_add(list, entry2);
+ LONGS_EQUAL(2, list->size);
- arrayList_add(list, entry3);
- LONGS_EQUAL(3, list->size);
+ arrayList_add(list, entry3);
+ LONGS_EQUAL(3, list->size);
- free(entry);
- free(entry2);
- free(entry3);
+ free(entry);
+ free(entry2);
+ free(entry3);
}
TEST(array_list, isEmpty){
- arrayList_clear(list);
- LONGS_EQUAL(0, list->size);
- CHECK(arrayList_isEmpty(list));
+ arrayList_clear(list);
+ LONGS_EQUAL(0, list->size);
+ CHECK(arrayList_isEmpty(list));
}
TEST(array_list, contains){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = NULL;
- bool contains;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = NULL;
+ bool contains;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
+ arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
- CHECK(arrayList_contains(list, entry));
- CHECK(arrayList_contains(list, entry2));
- contains = arrayList_contains(list, NULL);
- CHECK(!contains);
+ CHECK(arrayList_contains(list, entry));
+ CHECK(arrayList_contains(list, entry2));
+ contains = arrayList_contains(list, NULL);
+ CHECK(!contains);
- arrayList_add(list, entry3);
+ arrayList_add(list, entry3);
- CHECK(arrayList_contains(list, entry3));
+ CHECK(arrayList_contains(list, entry3));
- free(entry);
- free(entry2);
+ free(entry);
+ free(entry2);
}
TEST(array_list, indexOf){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
+ arrayList_add(list, entry);
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
- LONGS_EQUAL(0, arrayList_indexOf(list, entry));
- LONGS_EQUAL(1, arrayList_indexOf(list, entry2));
- LONGS_EQUAL(0, arrayList_lastIndexOf(list, entry));
- LONGS_EQUAL(4, arrayList_lastIndexOf(list, entry2));
+ LONGS_EQUAL(0, arrayList_indexOf(list, entry));
+ LONGS_EQUAL(1, arrayList_indexOf(list, entry2));
+ LONGS_EQUAL(0, arrayList_lastIndexOf(list, entry));
+ LONGS_EQUAL(4, arrayList_lastIndexOf(list, entry2));
- free(entry);
- free(entry2);
+ free(entry);
+ free(entry2);
}
TEST(array_list, get){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = NULL;
- char * get;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = NULL;
+ char * get;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- get = (char*) arrayList_get(list, 0);
- STRCMP_EQUAL(entry, get);
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry, get);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
- arrayList_add(list, entry3);
+ arrayList_add(list, entry3);
- get = (char*) arrayList_get(list, 2);
- CHECK(get == NULL);
+ get = (char*) arrayList_get(list, 2);
+ CHECK(get == NULL);
- get = (char*) arrayList_get(list, 42);
- CHECK(get == NULL);
+ get = (char*) arrayList_get(list, 42);
+ CHECK(get == NULL);
- free(entry);
- free(entry2);
+ free(entry);
+ free(entry2);
}
TEST(array_list, set){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- char * get;
- char * old;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ char * old;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
- old = (char*) arrayList_set(list, 1, entry3);
- STRCMP_EQUAL(entry2, old);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry3, get);
+ old = (char*) arrayList_set(list, 1, entry3);
+ STRCMP_EQUAL(entry2, old);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
- free(entry);
- free(entry2);
- free(entry3);
+ free(entry);
+ free(entry2);
+ free(entry3);
}
TEST(array_list, add){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- char * get;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
- arrayList_addIndex(list, 1, entry3);
+ arrayList_addIndex(list, 1, entry3);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry3, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
- get = (char*) arrayList_get(list, 2);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 2);
+ STRCMP_EQUAL(entry2, get);
- free(entry);
- free(entry2);
- free(entry3);
+ free(entry);
+ free(entry2);
+ free(entry3);
}
TEST(array_list, addAll){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- char * get;
- array_list_pt toAdd;
- bool changed;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ array_list_pt toAdd;
+ bool changed;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_create(&toAdd);
- arrayList_add(toAdd, entry);
- arrayList_add(toAdd, entry2);
+ arrayList_create(&toAdd);
+ arrayList_add(toAdd, entry);
+ arrayList_add(toAdd, entry2);
- arrayList_add(list, entry3);
+ arrayList_add(list, entry3);
- get = (char*) arrayList_get(list, 0);
- STRCMP_EQUAL(entry3, get);
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry3, get);
- changed = arrayList_addAll(list, toAdd);
- CHECK(changed);
- LONGS_EQUAL(3, arrayList_size(list));
+ changed = arrayList_addAll(list, toAdd);
+ CHECK(changed);
+ LONGS_EQUAL(3, arrayList_size(list));
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry, get);
- get = (char*) arrayList_get(list, 2);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 2);
+ STRCMP_EQUAL(entry2, get);
- free(entry);
- free(entry2);
- free(entry3);
- arrayList_destroy(toAdd);
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayList_destroy(toAdd);
}
TEST(array_list, remove){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- char * get;
- char * removed;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ char * removed;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry2, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
- // Remove first entry
- removed = (char*) arrayList_remove(list, 0);
- STRCMP_EQUAL(entry, removed);
+ // Remove first entry
+ removed = (char*) arrayList_remove(list, 0);
+ STRCMP_EQUAL(entry, removed);
- // Check the new first entry
- get = (char*) arrayList_get(list, 0);
- STRCMP_EQUAL(entry2, get);
+ // Check the new first entry
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry2, get);
- // Add a new entry
- arrayList_add(list, entry3);
+ // Add a new entry
+ arrayList_add(list, entry3);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry3, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
- free(entry);
- free(entry2);
- free(entry3);
+ free(entry);
+ free(entry2);
+ free(entry3);
}
TEST(array_list, removeElement){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- char * get;
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- // Remove entry
- CHECK(arrayList_removeElement(list, entry));
+ // Remove entry
+ CHECK(arrayList_removeElement(list, entry));
- // Check the new first element
- get = (char*) arrayList_get(list, 0);
- STRCMP_EQUAL(entry2, get);
+ // Check the new first element
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry2, get);
- // Add a new entry
- arrayList_add(list, entry3);
+ // Add a new entry
+ arrayList_add(list, entry3);
- get = (char*) arrayList_get(list, 1);
- STRCMP_EQUAL(entry3, get);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
- free(entry);
- free(entry2);
- free(entry3);
+ free(entry);
+ free(entry2);
+ free(entry3);
}
TEST(array_list, clear){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
- arrayList_clear(list);
+ arrayList_clear(list);
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
- LONGS_EQUAL(2, arrayList_size(list));
- arrayList_clear(list);
- LONGS_EQUAL(0, arrayList_size(list));
+ LONGS_EQUAL(2, arrayList_size(list));
+ arrayList_clear(list);
+ LONGS_EQUAL(0, arrayList_size(list));
- free(entry);
- free(entry2);
+ free(entry);
+ free(entry2);
}
//----------------------ARRAY LIST ITERATOR TESTS----------------------
TEST(array_list_iterator, create){
- array_list_iterator_pt it_list = arrayListIterator_create(list);
- CHECK(it_list != NULL);
- POINTERS_EQUAL(list, it_list->list);
- arrayListIterator_destroy(it_list);
+ array_list_iterator_pt it_list = arrayListIterator_create(list);
+ CHECK(it_list != NULL);
+ POINTERS_EQUAL(list, it_list->list);
+ arrayListIterator_destroy(it_list);
}
TEST(array_list_iterator, hasNext){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- array_list_iterator_pt it_list;
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
- arrayList_add(list, entry3);
- it_list = arrayListIterator_create(list);
- CHECK(arrayListIterator_hasNext(it_list));
-
- arrayListIterator_next(it_list);
- CHECK(arrayListIterator_hasNext(it_list));
-
- arrayListIterator_next(it_list);
- CHECK(arrayListIterator_hasNext(it_list));
-
- arrayListIterator_next(it_list);
- CHECK(!arrayListIterator_hasNext(it_list));
-
- free(entry);
- free(entry2);
- free(entry3);
- arrayListIterator_destroy(it_list);
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+ it_list = arrayListIterator_create(list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(!arrayListIterator_hasNext(it_list));
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
}
TEST(array_list_iterator, hasPrevious){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- array_list_iterator_pt it_list;
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
- arrayList_add(list, entry3);
-
- it_list = arrayListIterator_create(list);
- arrayListIterator_next(it_list);
- arrayListIterator_next(it_list);
- arrayListIterator_next(it_list);
- CHECK(arrayListIterator_hasPrevious(it_list));
-
- arrayListIterator_previous(it_list);
- CHECK(arrayListIterator_hasPrevious(it_list));
-
- arrayListIterator_previous(it_list);
- CHECK(arrayListIterator_hasPrevious(it_list));
-
- arrayListIterator_previous(it_list);
- CHECK(!arrayListIterator_hasPrevious(it_list));
-
- free(entry);
- free(entry2);
- free(entry3);
- arrayListIterator_destroy(it_list);
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+
+ it_list = arrayListIterator_create(list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(!arrayListIterator_hasPrevious(it_list));
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
}
TEST(array_list_iterator, next){
- char * entry = my_strdup("entry");
- char * entry2 = my_strdup("entry2");
- char * entry3 = my_strdup("entry3");
- array_list_iterator_pt it_list;
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
- arrayList_add(list, entry3);
- it_list = arrayListIterator_create(list);
- STRCMP_EQUAL(entry, (char*) arrayListIterator_next(it_list));
- STRCMP_EQUAL(entry2, (char*) arrayListIterator_next(it_list));
- STRCMP_EQUAL(entry3, (char*) arrayListIterator_next(it_list));
- POINTERS_EQUAL(NULL, arrayListIterator_next(it_list));
-
- //mess up the expected and real changecount, code should check and handle
- arrayList_add(list, entry);
- arrayListIterator_next(it_list);
-
- free(entry);
- free(entry2);
- free(entry3);
- arrayListIterator_destroy(it_list);
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+ it_list = arrayListIterator_create(list);
+ STRCMP_EQUAL(entry, (char*) arrayListIterator_next(it_list));
+ STRCMP_EQUAL(entry2, (char*) arrayListIterator_next(it_list));
+ STRCMP_EQUAL(entry3, (char*) arrayListIterator_next(it_list));
+ POINTERS_EQUAL(NULL, arrayListIterator_next(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayList_add(list, entry);
+ arrayListIterator_next(it_list);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
}
TEST(array_list_iterator, previous){
- char * value = my_strdup("entry");
- char * value2 = my_strdup("entry2");
- char * value3 = my_strdup("entry3");
- array_list_iterator_pt it_list;
-
- arrayList_add(list, value);
- arrayList_add(list, value2);
- arrayList_add(list, value3);
- it_list = arrayListIterator_create(list);
-
- arrayListIterator_next(it_list);
- arrayListIterator_next(it_list);
- arrayListIterator_next(it_list);
- STRCMP_EQUAL(value3, (char*) arrayListIterator_previous(it_list));
- STRCMP_EQUAL(value2, (char*) arrayListIterator_previous(it_list));
- STRCMP_EQUAL(value, (char*) arrayListIterator_previous(it_list));
- POINTERS_EQUAL(NULL, arrayListIterator_previous(it_list));
-
- //mess up the expected and real changecount, code should check and handle
- arrayListIterator_destroy(it_list);
- it_list = arrayListIterator_create(list);
- arrayList_add(list, value);
- arrayListIterator_previous(it_list);
-
- free(value);
- free(value2);
- free(value3);
- arrayListIterator_destroy(it_list);
+ char * value = my_strdup("entry");
+ char * value2 = my_strdup("entry2");
+ char * value3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, value);
+ arrayList_add(list, value2);
+ arrayList_add(list, value3);
+ it_list = arrayListIterator_create(list);
+
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ STRCMP_EQUAL(value3, (char*) arrayListIterator_previous(it_list));
+ STRCMP_EQUAL(value2, (char*) arrayListIterator_previous(it_list));
+ STRCMP_EQUAL(value, (char*) arrayListIterator_previous(it_list));
+ POINTERS_EQUAL(NULL, arrayListIterator_previous(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayListIterator_destroy(it_list);
+ it_list = arrayListIterator_create(list);
+ arrayList_add(list, value);
+ arrayListIterator_previous(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ arrayListIterator_destroy(it_list);
}
TEST(array_list_iterator, remove){
- char * value = my_strdup("entry");
- char * value2 = my_strdup("entry2");
- char * value3 = my_strdup("entry3");
- array_list_iterator_pt it_list;
-
- arrayList_add(list, value);
- arrayList_add(list, value2);
- arrayList_add(list, value3);
- it_list = arrayListIterator_create(list);
-
- LONGS_EQUAL(3, list->size);
- STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) arrayList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) arrayList_get(list, 2));
-
- arrayListIterator_next(it_list);
- arrayListIterator_next(it_list);
- arrayListIterator_remove(it_list);
- LONGS_EQUAL(2, list->size);
- STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
- STRCMP_EQUAL(value3, (char*) arrayList_get(list, 1));
-
- //mess up the expected and real changecount, code should check and handle
- arrayList_add(list, value);
- arrayListIterator_remove(it_list);
-
- free(value);
- free(value2);
- free(value3);
- arrayListIterator_destroy(it_list);
+ char * value = my_strdup("entry");
+ char * value2 = my_strdup("entry2");
+ char * value3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, value);
+ arrayList_add(list, value2);
+ arrayList_add(list, value3);
+ it_list = arrayListIterator_create(list);
+
+ LONGS_EQUAL(3, list->size);
+ STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) arrayList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) arrayList_get(list, 2));
+
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_remove(it_list);
+ LONGS_EQUAL(2, list->size);
+ STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) arrayList_get(list, 1));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayList_add(list, value);
+ arrayListIterator_remove(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ arrayListIterator_destroy(it_list);
}
diff --git a/libs/utils/private/test/celix_threads_test.cpp b/libs/utils/private/test/celix_threads_test.cpp
index 1565c3a..7520445 100644
--- a/libs/utils/private/test/celix_threads_test.cpp
+++ b/libs/utils/private/test/celix_threads_test.cpp
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list_test.cpp
*
- * \date Sep 15, 2015
- * \author Menno van der Graaf & Alexander
- * \copyright Apache License, Version 2.0
+ * \date Sep 15, 2015
+ * \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 <unistd.h>
@@ -40,36 +41,36 @@ extern "C" {
static char* my_strdup(const char* s) {
- if (s == NULL) {
- return NULL;
- }
+ if (s == NULL) {
+ return NULL;
+ }
- size_t len = strlen(s);
+ size_t len = strlen(s);
- char *d = (char*) calloc(len + 1, sizeof(char));
+ char *d = (char*) calloc(len + 1, sizeof(char));
- if (d == NULL) {
- return NULL;
- }
+ if (d == NULL) {
+ return NULL;
+ }
- strncpy(d, s, len);
- return d;
+ strncpy(d, s, len);
+ return d;
}
static int celix_thread_t_equals(const void * object, const void * compareTo){
- celix_thread_t * thread1 = (celix_thread_t*) object;
- celix_thread_t * thread2 = (celix_thread_t*) compareTo;
+ celix_thread_t * thread1 = (celix_thread_t*) object;
+ celix_thread_t * thread2 = (celix_thread_t*) compareTo;
- return thread1->thread == thread2->thread &&
- thread1->threadInitialized == thread2->threadInitialized;
+ return thread1->thread == thread2->thread &&
+ thread1->threadInitialized == thread2->threadInitialized;
}
static const char * celix_thread_t_toString(const void * object){
- celix_thread_t * thread = (celix_thread_t*) object;
- char buff[512];
- snprintf(buff, 512, "thread: %lu, threadInitialized: %s", (unsigned long)thread->thread, (thread->threadInitialized ? "true" : "false"));
+ celix_thread_t * thread = (celix_thread_t*) object;
+ char buff[512];
+ snprintf(buff, 512, "thread: %lu, threadInitialized: %s", (unsigned long)thread->thread, (thread->threadInitialized ? "true" : "false"));
- return my_strdup(buff);
+ return my_strdup(buff);
}
//----------------------TEST THREAD FUNCTION DECLARATIONS----------------------
@@ -86,446 +87,446 @@ static int thread_test_func_recur_lock(celix_thread_mutex_t*, int);
static void * thread_test_func_kill(void*);
static void thread_test_func_kill_handler(int);
struct func_param{
- int i, i2;
- celix_thread_mutex_t mu, mu2;
- celix_thread_cond_t cond, cond2;
- celix_thread_once_t once_control;
- celix_thread_rwlock_t rwlock;
+ int i, i2;
+ celix_thread_mutex_t mu, mu2;
+ celix_thread_cond_t cond, cond2;
+ celix_thread_once_t once_control;
+ celix_thread_rwlock_t rwlock;
};
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
//----------------------TESTGROUP DEFINES----------------------
TEST_GROUP(celix_thread) {
- celix_thread thread;
+ celix_thread thread;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown(void) {
- }
+ void teardown(void) {
+ }
};
TEST_GROUP(celix_thread_kill) {
- celix_thread thread;
- struct sigaction sigact, sigactold;
+ celix_thread thread;
+ struct sigaction sigact, sigactold;
- void setup(void) {
- memset(&sigact, 0, sizeof(sigact));
- sigact.sa_handler = thread_test_func_kill_handler;
- sigaction(SIGUSR1, &sigact, &sigactold);
+ void setup(void) {
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = thread_test_func_kill_handler;
+ sigaction(SIGUSR1, &sigact, &sigactold);
- mock_c()->installComparator("celix_thread_t", celix_thread_t_equals, celix_thread_t_toString);
- }
+ mock_c()->installComparator("celix_thread_t", celix_thread_t_equals, celix_thread_t_toString);
+ }
- void teardown(void) {
- sigaction(SIGUSR1, &sigactold, &sigact);
+ void teardown(void) {
+ sigaction(SIGUSR1, &sigactold, &sigact);
- mock_c()->removeAllComparatorsAndCopiers();
- }
+ mock_c()->removeAllComparatorsAndCopiers();
+ }
};
TEST_GROUP(celix_thread_mutex) {
- celix_thread thread;
- celix_thread_mutex_t mu;
+ celix_thread thread;
+ celix_thread_mutex_t mu;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown(void) {
- }
+ void teardown(void) {
+ }
};
TEST_GROUP(celix_thread_condition) {
- celix_thread thread;
- celix_thread_mutex_t mu;
- celix_thread_cond_t cond;
+ celix_thread thread;
+ celix_thread_mutex_t mu;
+ celix_thread_cond_t cond;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown(void) {
- }
+ void teardown(void) {
+ }
};
TEST_GROUP(celix_thread_rwlock) {
- celix_thread thread;
+ celix_thread thread;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown(void) {
- }
+ void teardown(void) {
+ }
};
//----------------------CELIX THREADS TESTS----------------------
TEST(celix_thread, create) {
- int ret;
- char * test_str;
+ int ret;
+ char * test_str;
- ret = celixThread_create(&thread, NULL, &thread_test_func_create,
- &test_str);
- LONGS_EQUAL(CELIX_SUCCESS, ret);
- celixThread_join(thread, NULL);
+ ret = celixThread_create(&thread, NULL, &thread_test_func_create,
+ &test_str);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
+ celixThread_join(thread, NULL);
- CHECK(test_str != NULL);
- STRCMP_EQUAL("SUCCESS", test_str);
+ CHECK(test_str != NULL);
+ STRCMP_EQUAL("SUCCESS", test_str);
- free(test_str);
+ free(test_str);
}
TEST(celix_thread, exit) {
- int ret, *status;
+ int ret, *status;
- ret = celixThread_create(&thread, NULL, &thread_test_func_exit, NULL);
- LONGS_EQUAL(CELIX_SUCCESS, ret);
- celixThread_join(thread, (void**) &status);
- LONGS_EQUAL(666, *status);
- free(status);
+ ret = celixThread_create(&thread, NULL, &thread_test_func_exit, NULL);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
+ celixThread_join(thread, (void**) &status);
+ LONGS_EQUAL(666, *status);
+ free(status);
}
//HORRIBLE TEST
TEST(celix_thread, detach) {
- int ret;
+ int ret;
- celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
- ret = celixThread_detach(thread);
- LONGS_EQUAL(CELIX_SUCCESS, ret);
+ celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
+ ret = celixThread_detach(thread);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
}
TEST(celix_thread, self) {
- celix_thread thread2;
+ celix_thread thread2;
- celixThread_create(&thread, NULL, thread_test_func_self, &thread2);
- celixThread_join(thread, NULL);
- CHECK(celixThread_equals(thread, thread2));
+ celixThread_create(&thread, NULL, thread_test_func_self, &thread2);
+ celixThread_join(thread, NULL);
+ CHECK(celixThread_equals(thread, thread2));
}
TEST(celix_thread, initialized) {
- CHECK(!celixThread_initialized(thread));
- celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
- CHECK(celixThread_initialized(thread));
- celixThread_detach(thread);
+ CHECK(!celixThread_initialized(thread));
+ celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
+ CHECK(celixThread_initialized(thread));
+ celixThread_detach(thread);
}
TEST(celix_thread, once) {
- int *status;
- celix_thread thread2;
- struct func_param * params = (struct func_param*) calloc(1,
- sizeof(struct func_param));
+ int *status;
+ celix_thread thread2;
+ struct func_param * params = (struct func_param*) calloc(1,
+ sizeof(struct func_param));
- mock().expectOneCall("thread_test_func_once_init");
+ mock().expectOneCall("thread_test_func_once_init");
- celixThread_create(&thread, NULL, &thread_test_func_once, params);
- celixThread_join(thread, (void**) &status);
+ celixThread_create(&thread, NULL, &thread_test_func_once, params);
+ celixThread_join(thread, (void**) &status);
- celixThread_create(&thread2, NULL, &thread_test_func_once, params);
- celixThread_join(thread2, (void**) &status);
+ celixThread_create(&thread2, NULL, &thread_test_func_once, params);
+ celixThread_join(thread2, (void**) &status);
- free(params);
+ free(params);
- mock().checkExpectations();
- mock().clear();
+ mock().checkExpectations();
+ mock().clear();
}
//----------------------CELIX THREADS KILL TESTS----------------------
TEST(celix_thread_kill, kill){
- int * ret;
- celixThread_create(&thread, NULL, thread_test_func_kill, NULL);
- sleep(2);
+ int * ret;
+ celixThread_create(&thread, NULL, thread_test_func_kill, NULL);
+ sleep(2);
- mock().expectOneCall("thread_test_func_kill_handler")
- .withParameter("signo", SIGUSR1)
- .withParameterOfType("celix_thread_t", "inThread", (const void*) &thread);
+ mock().expectOneCall("thread_test_func_kill_handler")
+ .withParameter("signo", SIGUSR1)
+ .withParameterOfType("celix_thread_t", "inThread", (const void*) &thread);
- celixThread_kill(thread, SIGUSR1);
- celixThread_join(thread, (void**)&ret);
+ celixThread_kill(thread, SIGUSR1);
+ celixThread_join(thread, (void**)&ret);
- LONGS_EQUAL(-1, *ret);
- free(ret);
+ LONGS_EQUAL(-1, *ret);
+ free(ret);
- mock().checkExpectations();
- mock().clear();
+ mock().checkExpectations();
+ mock().clear();
}
//----------------------CELIX THREADS MUTEX TESTS----------------------
TEST(celix_thread_mutex, create) {
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_create(&mu, NULL));
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_destroy(&mu));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_create(&mu, NULL));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_destroy(&mu));
}
//check normal lock behaviour
TEST(celix_thread_mutex, lock) {
- struct func_param * params = (struct func_param*) calloc(1,
- sizeof(struct func_param));
+ struct func_param * params = (struct func_param*) calloc(1,
+ sizeof(struct func_param));
- celixThreadMutex_create(¶ms->mu, NULL);
+ celixThreadMutex_create(¶ms->mu, NULL);
- celixThreadMutex_lock(¶ms->mu);
- celixThread_create(&thread, NULL, thread_test_func_lock, params);
+ celixThreadMutex_lock(¶ms->mu);
+ celixThread_create(&thread, NULL, thread_test_func_lock, params);
- sleep(2);
+ sleep(2);
- LONGS_EQUAL(0, params->i);
+ LONGS_EQUAL(0, params->i);
- //possible race condition, not perfect test
- celixThreadMutex_unlock(¶ms->mu);
+ //possible race condition, not perfect test
+ celixThreadMutex_unlock(¶ms->mu);
- sleep(2);
+ sleep(2);
- celixThreadMutex_lock(¶ms->mu2);
- LONGS_EQUAL(666, params->i);
- celixThreadMutex_unlock(¶ms->mu2);
- celixThread_join(thread, NULL);
- free(params);
+ celixThreadMutex_lock(¶ms->mu2);
+ LONGS_EQUAL(666, params->i);
+ celixThreadMutex_unlock(¶ms->mu2);
+ celixThread_join(thread, NULL);
+ free(params);
}
TEST(celix_thread_mutex, attrCreate) {
- celix_thread_mutexattr_t mu_attr;
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_create(&mu_attr));
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_destroy(&mu_attr));
+ celix_thread_mutexattr_t mu_attr;
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_create(&mu_attr));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_destroy(&mu_attr));
}
TEST(celix_thread_mutex, attrSettype) {
- celix_thread_mutex_t mu;
- celix_thread_mutexattr_t mu_attr;
- celixThreadMutexAttr_create(&mu_attr);
-
- //test recursive mutex
- celixThreadMutexAttr_settype(&mu_attr, CELIX_THREAD_MUTEX_RECURSIVE);
- celixThreadMutex_create(&mu, &mu_attr);
- //if program doesnt deadlock: success! also check factorial of 10, for reasons unknown
- LONGS_EQUAL(3628800, thread_test_func_recur_lock(&mu, 10));
- celixThreadMutex_destroy(&mu);
-
- //test deadlock check mutex
- celixThreadMutexAttr_settype(&mu_attr, CELIX_THREAD_MUTEX_ERRORCHECK);
- celixThreadMutex_create(&mu, &mu_attr);
- //get deadlock error
- celixThreadMutex_lock(&mu);
- CHECK(celixThreadMutex_lock(&mu) != CELIX_SUCCESS);
- //do not get deadlock error
- celixThreadMutex_unlock(&mu);
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_lock(&mu));
- //get unlock error
- celixThreadMutex_unlock(&mu);
- CHECK(celixThreadMutex_unlock(&mu) != CELIX_SUCCESS);
-
- celixThreadMutex_destroy(&mu);
- celixThreadMutexAttr_destroy(&mu_attr);
+ celix_thread_mutex_t mu;
+ celix_thread_mutexattr_t mu_attr;
+ celixThreadMutexAttr_create(&mu_attr);
+
+ //test recursive mutex
+ celixThreadMutexAttr_settype(&mu_attr, CELIX_THREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&mu, &mu_attr);
+ //if program doesnt deadlock: success! also check factorial of 10, for reasons unknown
+ LONGS_EQUAL(3628800, thread_test_func_recur_lock(&mu, 10));
+ celixThreadMutex_destroy(&mu);
+
+ //test deadlock check mutex
+ celixThreadMutexAttr_settype(&mu_attr, CELIX_THREAD_MUTEX_ERRORCHECK);
+ celixThreadMutex_create(&mu, &mu_attr);
+ //get deadlock error
+ celixThreadMutex_lock(&mu);
+ CHECK(celixThreadMutex_lock(&mu) != CELIX_SUCCESS);
+ //do not get deadlock error
+ celixThreadMutex_unlock(&mu);
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_lock(&mu));
+ //get unlock error
+ celixThreadMutex_unlock(&mu);
+ CHECK(celixThreadMutex_unlock(&mu) != CELIX_SUCCESS);
+
+ celixThreadMutex_destroy(&mu);
+ celixThreadMutexAttr_destroy(&mu_attr);
}
//----------------------CELIX THREAD CONDITIONS TESTS----------------------
TEST(celix_thread_condition, init) {
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_init(&cond, NULL));
- LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_destroy(&cond));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_init(&cond, NULL));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_destroy(&cond));
}
//test wait and signal
TEST(celix_thread_condition, wait) {
- struct func_param * param = (struct func_param*) calloc(1,
- sizeof(struct func_param));
- celixThreadMutex_create(¶m->mu, NULL);
- celixThreadCondition_init(¶m->cond, NULL);
+ struct func_param * param = (struct func_param*) calloc(1,
+ sizeof(struct func_param));
+ celixThreadMutex_create(¶m->mu, NULL);
+ celixThreadCondition_init(¶m->cond, NULL);
- celixThreadMutex_lock(¶m->mu);
+ celixThreadMutex_lock(¶m->mu);
- sleep(2);
+ sleep(2);
- celixThread_create(&thread, NULL, thread_test_func_cond_wait, param);
- LONGS_EQUAL(0, param->i);
+ celixThread_create(&thread, NULL, thread_test_func_cond_wait, param);
+ LONGS_EQUAL(0, param->i);
- celixThreadCondition_wait(¶m->cond, ¶m->mu);
- LONGS_EQUAL(666, param->i);
- celixThreadMutex_unlock(¶m->mu);
+ celixThreadCondition_wait(¶m->cond, ¶m->mu);
+ LONGS_EQUAL(666, param->i);
+ celixThreadMutex_unlock(¶m->mu);
- celixThread_join(thread, NULL);
- free(param);
+ celixThread_join(thread, NULL);
+ free(param);
}
//test wait and broadcast on multiple threads
TEST(celix_thread_condition, broadcast) {
- celix_thread_t thread2;
- struct func_param * param = (struct func_param*) calloc(1,sizeof(struct func_param));
- celixThreadMutex_create(¶m->mu, NULL);
- celixThreadMutex_create(¶m->mu2, NULL);
- celixThreadCondition_init(¶m->cond, NULL);
+ celix_thread_t thread2;
+ struct func_param * param = (struct func_param*) calloc(1,sizeof(struct func_param));
+ celixThreadMutex_create(¶m->mu, NULL);
+ celixThreadMutex_create(¶m->mu2, NULL);
+ celixThreadCondition_init(¶m->cond, NULL);
- celixThread_create(&thread, NULL, thread_test_func_cond_broadcast, param);
- celixThread_create(&thread2, NULL, thread_test_func_cond_broadcast, param);
+ celixThread_create(&thread, NULL, thread_test_func_cond_broadcast, param);
+ celixThread_create(&thread2, NULL, thread_test_func_cond_broadcast, param);
- sleep(1);
- celixThreadMutex_lock(¶m->mu);
- LONGS_EQUAL(0, param->i);
- celixThreadMutex_unlock(¶m->mu);
+ sleep(1);
+ celixThreadMutex_lock(¶m->mu);
+ LONGS_EQUAL(0, param->i);
+ celixThreadMutex_unlock(¶m->mu);
- celixThreadMutex_lock(¶m->mu);
- celixThreadCondition_broadcast(¶m->cond);
- celixThreadMutex_unlock(¶m->mu);
- sleep(1);
- celixThreadMutex_lock(¶m->mu);
- LONGS_EQUAL(2, param->i);
- celixThreadMutex_unlock(¶m->mu);
+ celixThreadMutex_lock(¶m->mu);
+ celixThreadCondition_broadcast(¶m->cond);
+ celixThreadMutex_unlock(¶m->mu);
+ sleep(1);
+ celixThreadMutex_lock(¶m->mu);
+ LONGS_EQUAL(2, param->i);
+ celixThreadMutex_unlock(¶m->mu);
- celixThread_join(thread, NULL);
- celixThread_join(thread2, NULL);
- free(param);
+ celixThread_join(thread, NULL);
+ celixThread_join(thread2, NULL);
+ free(param);
}
//----------------------CELIX READ-WRITE LOCK TESTS----------------------
TEST(celix_thread_rwlock, create){
- celix_thread_rwlock_t lock;
- celix_status_t status;
- status = celixThreadRwlock_create(&lock, NULL);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- status = celixThreadRwlock_destroy(&lock);
- LONGS_EQUAL(CELIX_SUCCESS, status);
+ celix_thread_rwlock_t lock;
+ celix_status_t status;
+ status = celixThreadRwlock_create(&lock, NULL);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ status = celixThreadRwlock_destroy(&lock);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
}
TEST(celix_thread_rwlock, readLock){
- int status;
- celix_thread_rwlock_t lock;
- //struct func_param * param = (struct func_param*) calloc(1,sizeof(struct func_param));
+ int status;
+ celix_thread_rwlock_t lock;
+ //struct func_param * param = (struct func_param*) calloc(1,sizeof(struct func_param));
- celixThreadRwlock_create(&lock, NULL);
+ celixThreadRwlock_create(&lock, NULL);
- status = celixThreadRwlock_readLock(&lock);
- LONGS_EQUAL(0, status);
- status = celixThreadRwlock_readLock(&lock);
- LONGS_EQUAL(0, status);
- status = celixThreadRwlock_unlock(&lock);
- LONGS_EQUAL(0, status);
- status = celixThreadRwlock_unlock(&lock);
- LONGS_EQUAL(0, status);
+ status = celixThreadRwlock_readLock(&lock);
+ LONGS_EQUAL(0, status);
+ status = celixThreadRwlock_readLock(&lock);
+ LONGS_EQUAL(0, status);
+ status = celixThreadRwlock_unlock(&lock);
+ LONGS_EQUAL(0, status);
+ status = celixThreadRwlock_unlock(&lock);
+ LONGS_EQUAL(0, status);
- celixThreadRwlock_destroy(&lock);
+ celixThreadRwlock_destroy(&lock);
}
TEST(celix_thread_rwlock, writeLock){
- int status;
- celix_thread_rwlock_t lock;
- celixThreadRwlock_create(&lock, NULL);
+ int status;
+ celix_thread_rwlock_t lock;
+ celixThreadRwlock_create(&lock, NULL);
- status = celixThreadRwlock_writeLock(&lock);
- LONGS_EQUAL(0, status);
- status = celixThreadRwlock_writeLock(&lock);
- //EDEADLK ErNo: Resource deadlock avoided
- LONGS_EQUAL(EDEADLK, status);
+ status = celixThreadRwlock_writeLock(&lock);
+ LONGS_EQUAL(0, status);
+ status = celixThreadRwlock_writeLock(&lock);
+ //EDEADLK ErNo: Resource deadlock avoided
+ LONGS_EQUAL(EDEADLK, status);
- celixThreadRwlock_unlock(&lock);
+ celixThreadRwlock_unlock(&lock);
}
TEST(celix_thread_rwlock, attr){
- celix_thread_rwlockattr_t attr;
- celixThreadRwlockAttr_create(&attr);
- celixThreadRwlockAttr_destroy(&attr);
+ celix_thread_rwlockattr_t attr;
+ celixThreadRwlockAttr_create(&attr);
+ celixThreadRwlockAttr_destroy(&attr);
}
//----------------------TEST THREAD FUNCTION DEFINES----------------------
extern "C" {
static void * thread_test_func_create(void * arg) {
- char ** test_str = (char**) arg;
- *test_str = my_strdup("SUCCESS");
+ char ** test_str = (char**) arg;
+ *test_str = my_strdup("SUCCESS");
- return NULL;
+ return NULL;
}
static void * thread_test_func_exit(void *) {
- int *pi = (int*) calloc(1, sizeof(int));
- *pi = 666;
+ int *pi = (int*) calloc(1, sizeof(int));
+ *pi = 666;
- celixThread_exit(pi);
- return NULL;
+ celixThread_exit(pi);
+ return NULL;
}
static void * thread_test_func_detach(void *) {
- return NULL;
+ return NULL;
}
static void * thread_test_func_self(void * arg) {
- *((celix_thread*) arg) = celixThread_self();
- return NULL;
+ *((celix_thread*) arg) = celixThread_self();
+ return NULL;
}
static void * thread_test_func_once(void * arg) {
- struct func_param *param = (struct func_param *) arg;
- celixThread_once(¶m->once_control, thread_test_func_once_init);
+ struct func_param *param = (struct func_param *) arg;
+ celixThread_once(¶m->once_control, thread_test_func_once_init);
- return NULL;
+ return NULL;
}
static void thread_test_func_once_init(void) {
- mock_c()->actualCall("thread_test_func_once_init");
+ mock_c()->actualCall("thread_test_func_once_init");
}
static void * thread_test_func_lock(void *arg) {
- struct func_param *param = (struct func_param *) arg;
+ struct func_param *param = (struct func_param *) arg;
- celixThreadMutex_lock(¶m->mu2);
- celixThreadMutex_lock(¶m->mu);
- param->i = 666;
- celixThreadMutex_unlock(¶m->mu);
- celixThreadMutex_unlock(¶m->mu2);
+ celixThreadMutex_lock(¶m->mu2);
+ celixThreadMutex_lock(¶m->mu);
+ param->i = 666;
+ celixThreadMutex_unlock(¶m->mu);
+ celixThreadMutex_unlock(¶m->mu2);
- return NULL;
+ return NULL;
}
static void * thread_test_func_cond_wait(void *arg) {
- struct func_param *param = (struct func_param *) arg;
+ struct func_param *param = (struct func_param *) arg;
- celixThreadMutex_lock(¶m->mu);
+ celixThreadMutex_lock(¶m->mu);
- param->i = 666;
+ param->i = 666;
- celixThreadCondition_signal(¶m->cond);
- celixThreadMutex_unlock(¶m->mu);
- return NULL;
+ celixThreadCondition_signal(¶m->cond);
+ celixThreadMutex_unlock(¶m->mu);
+ return NULL;
}
static void * thread_test_func_cond_broadcast(void *arg) {
- struct func_param *param = (struct func_param *) arg;
+ struct func_param *param = (struct func_param *) arg;
- celixThreadMutex_lock(¶m->mu);
- celixThreadCondition_wait(¶m->cond, ¶m->mu);
- celixThreadMutex_unlock(¶m->mu);
- celixThreadMutex_lock(¶m->mu);
- param->i++;
- celixThreadMutex_unlock(¶m->mu);
- return NULL;
+ celixThreadMutex_lock(¶m->mu);
+ celixThreadCondition_wait(¶m->cond, ¶m->mu);
+ celixThreadMutex_unlock(¶m->mu);
+ celixThreadMutex_lock(¶m->mu);
+ param->i++;
+ celixThreadMutex_unlock(¶m->mu);
+ return NULL;
}
static int thread_test_func_recur_lock(celix_thread_mutex_t *mu, int i) {
- int temp;
- if (i == 1) {
- return 1;
- } else {
- celixThreadMutex_lock(mu);
- temp = thread_test_func_recur_lock(mu, i - 1);
- temp *= i;
- celixThreadMutex_unlock(mu);
- return temp;
- }
+ int temp;
+ if (i == 1) {
+ return 1;
+ } else {
+ celixThreadMutex_lock(mu);
+ temp = thread_test_func_recur_lock(mu, i - 1);
+ temp *= i;
+ celixThreadMutex_unlock(mu);
+ return temp;
+ }
}
static void * thread_test_func_kill(void __attribute__((unused)) *arg){
- int * ret = (int*) malloc(sizeof(*ret));
- //sleep for a about a minute, or until a kill signal (USR1) is received
- *ret = usleep(60000000);
- return ret;
+ int * ret = (int*) malloc(sizeof(*ret));
+ //sleep for a about a minute, or until a kill signal (USR1) is received
+ *ret = usleep(60000000);
+ return ret;
}
static void thread_test_func_kill_handler(int signo){
- celix_thread_t inThread = celixThread_self();
+ celix_thread_t inThread = celixThread_self();
- mock_c()->actualCall("thread_test_func_kill_handler")
- ->withLongIntParameters("signo", signo)
- ->withParameterOfType("celix_thread_t", "inThread", (const void*) &inThread);
+ mock_c()->actualCall("thread_test_func_kill_handler")
+ ->withLongIntParameters("signo", signo)
+ ->withParameterOfType("celix_thread_t", "inThread", (const void*) &inThread);
}
}
diff --git a/libs/utils/private/test/filter_test.cpp b/libs/utils/private/test/filter_test.cpp
index 696e69d..e74fc80 100644
--- a/libs/utils/private/test/filter_test.cpp
+++ b/libs/utils/private/test/filter_test.cpp
@@ -213,7 +213,7 @@ TEST(filter, match_comparators){
CHECK_FALSE(result);
//cleanup
- properties_destroy(props);
+ celix_properties_destroy(props);
celix_filter_destroy(filter);
free(filter_str);
free(key);
@@ -422,7 +422,7 @@ TEST(filter, match_operators){
CHECK_FALSE(result);
//cleanup
- properties_destroy(props);
+ celix_properties_destroy(props);
celix_filter_destroy(filter);
free(filter_str);
free(key);
diff --git a/libs/utils/private/test/hash_map_test.cpp b/libs/utils/private/test/hash_map_test.cpp
index 8a050b0..1ec9e1f 100644
--- a/libs/utils/private/test/hash_map_test.cpp
+++ b/libs/utils/private/test/hash_map_test.cpp
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* hash_map_test.cpp
*
- * \date Sep 15, 2015
- * \author Menno van der Graaf & Alexander
- * \copyright Apache License, Version 2.0
+ * \date Sep 15, 2015
+ * \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>
@@ -40,1453 +41,1453 @@ extern "C"
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s){
- if(s==NULL){
- return NULL;
- }
+ if(s==NULL){
+ return NULL;
+ }
- size_t len = strlen(s);
+ size_t len = strlen(s);
- char *d = (char*) calloc (len + 1,sizeof(char));
+ char *d = (char*) calloc (len + 1,sizeof(char));
- if (d == NULL){
- return NULL;
- }
+ if (d == NULL){
+ return NULL;
+ }
- strncpy (d,s,len);
- return d;
+ strncpy (d,s,len);
+ return d;
}
//Callback functions
unsigned int test_hashKeyChar(const void * k) {
- char * str = (char *) k;
+ char * str = (char *) k;
- unsigned int hash = 1315423911;
- unsigned int i = 0;
- unsigned int len = strlen(str);
+ unsigned int hash = 1315423911;
+ unsigned int i = 0;
+ unsigned int len = strlen(str);
- for(i = 0; i < len; str++, i++)
- {
- hash ^= ((hash << 5) + (*str) + (hash >> 2));
- }
+ for(i = 0; i < len; str++, i++)
+ {
+ hash ^= ((hash << 5) + (*str) + (hash >> 2));
+ }
- return hash;
+ return hash;
}
unsigned int test_hashValueChar(const void * v) {
- (void)(v);
- return 0;
+ (void)(v);
+ return 0;
}
int test_equalsKeyChar(const void * k, const void * o) {
- return strcmp((char *)k, (char *) o) == 0;
+ return strcmp((char *)k, (char *) o) == 0;
}
int test_equalsValueChar(const void * v, const void * o) {
- return strcmp((char *)v, (char *) o) == 0;
+ return strcmp((char *)v, (char *) o) == 0;
}
//Tests group defines
TEST_GROUP(hash_map){
- hash_map_pt map;
-
- void setup() {
- map = hashMap_create(NULL, NULL, NULL, NULL);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
TEST_GROUP(hash_map_iterator){
- hash_map_pt map;
- hash_map_iterator_pt it_map;
-
- void setup() {
- map = hashMap_create(NULL, NULL, NULL, NULL);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+ hash_map_iterator_pt it_map;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
TEST_GROUP(hash_map_values){
- hash_map_pt map;
- hash_map_values_pt values;
-
- void setup() {
- map = hashMap_create(NULL, NULL, NULL, NULL);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+ hash_map_values_pt values;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
TEST_GROUP(hash_map_keySet){
- hash_map_pt map;
- hash_map_key_set_pt key_set;
-
- void setup() {
- map = hashMap_create(NULL, NULL, NULL, NULL);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+ hash_map_key_set_pt key_set;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
TEST_GROUP(hash_map_entrySet){
- hash_map_pt map;
- hash_map_entry_set_pt entry_set;
-
- void setup() {
- map = hashMap_create(NULL, NULL, NULL, NULL);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+ hash_map_entry_set_pt entry_set;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
TEST_GROUP(hash_map_hash) {
- hash_map_pt map;
-
- void setup(void) {
- map = hashMap_create(test_hashKeyChar, test_hashValueChar, test_equalsKeyChar, test_equalsValueChar);
- }
- void teardown() {
- hashMap_destroy(map, false, false);
- }
+ hash_map_pt map;
+
+ void setup(void) {
+ map = hashMap_create(test_hashKeyChar, test_hashValueChar, test_equalsKeyChar, test_equalsValueChar);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
};
//----------------------HASH MAP DATA MANAGEMENT TEST----------------------
TEST(hash_map, create){
- CHECK(map != NULL);
- LONGS_EQUAL(0, map->size);
- // This fails on windows due to dllimport providing a proxy for exported functions.
- POINTERS_EQUAL(hashMap_equals, map->equalsKey);
- POINTERS_EQUAL(hashMap_equals, map->equalsValue);
- POINTERS_EQUAL(hashMap_hashCode, map->hashKey);
- POINTERS_EQUAL(hashMap_hashCode, map->hashValue);
+ CHECK(map != NULL);
+ LONGS_EQUAL(0, map->size);
+ // This fails on windows due to dllimport providing a proxy for exported functions.
+ POINTERS_EQUAL(hashMap_equals, map->equalsKey);
+ POINTERS_EQUAL(hashMap_equals, map->equalsValue);
+ POINTERS_EQUAL(hashMap_hashCode, map->hashKey);
+ POINTERS_EQUAL(hashMap_hashCode, map->hashValue);
}
TEST(hash_map, size){
- char* key = my_strdup("key");
- char* value = my_strdup("value");
- char* key2 = my_strdup("key2");
- char* value2 = my_strdup("value2");
- char* key3 = my_strdup("key2");
- char* value3 = my_strdup("value3");
-
- LONGS_EQUAL(0, map->size);
-
- // Add one entry
- hashMap_put(map, key, value);
- LONGS_EQUAL(1, map->size);
-
- // Add second entry
- hashMap_put(map, key2, value2);
- LONGS_EQUAL(2, map->size);
-
- // Add entry using the same key, this does not overwrite an existing entry
- hashMap_put(map, key3, value3);
- LONGS_EQUAL(3, map->size);
-
- // Clear map
- hashMap_clear(map, true, true);
- LONGS_EQUAL(0, map->size);
+ char* key = my_strdup("key");
+ char* value = my_strdup("value");
+ char* key2 = my_strdup("key2");
+ char* value2 = my_strdup("value2");
+ char* key3 = my_strdup("key2");
+ char* value3 = my_strdup("value3");
+
+ LONGS_EQUAL(0, map->size);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+ LONGS_EQUAL(1, map->size);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+ LONGS_EQUAL(2, map->size);
+
+ // Add entry using the same key, this does not overwrite an existing entry
+ hashMap_put(map, key3, value3);
+ LONGS_EQUAL(3, map->size);
+
+ // Clear map
+ hashMap_clear(map, true, true);
+ LONGS_EQUAL(0, map->size);
}
TEST(hash_map, isEmpty){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
- // Add one entry
- hashMap_put(map, key, value);
- LONGS_EQUAL(1, map->size);
- CHECK(!hashMap_isEmpty(map));
+ // Add one entry
+ hashMap_put(map, key, value);
+ LONGS_EQUAL(1, map->size);
+ CHECK(!hashMap_isEmpty(map));
- // Remove entry
- hashMap_remove(map, key);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
+ // Remove entry
+ hashMap_remove(map, key);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
- free(key);
- free(value);
+ free(key);
+ free(value);
}
TEST(hash_map, get){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * neKey = my_strdup("notExisting");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * get;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- get = (char*) (char*) hashMap_get(map, key);
- STRCMP_EQUAL(value, get);
+ get = (char*) (char*) hashMap_get(map, key);
+ STRCMP_EQUAL(value, get);
- get = (char*) hashMap_get(map, key2);
- STRCMP_EQUAL(value2, get);
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(value2, get);
- get = (char*) hashMap_get(map, neKey);
- POINTERS_EQUAL(NULL, get);
+ get = (char*) hashMap_get(map, neKey);
+ POINTERS_EQUAL(NULL, get);
- get = (char*) hashMap_get(map, NULL);
- POINTERS_EQUAL(NULL, get);
+ get = (char*) hashMap_get(map, NULL);
+ POINTERS_EQUAL(NULL, get);
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
- get = (char*) hashMap_get(map, NULL);
- STRCMP_EQUAL(value3, get);
+ get = (char*) hashMap_get(map, NULL);
+ STRCMP_EQUAL(value3, get);
- free(neKey);
- hashMap_clear(map, true, true);
+ free(neKey);
+ hashMap_clear(map, true, true);
}
TEST(hash_map, containsKey){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * neKey = my_strdup("notExisting");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- CHECK(hashMap_containsKey(map, key));
- CHECK(hashMap_containsKey(map, key2));
- CHECK(!hashMap_containsKey(map, neKey));
- CHECK(!hashMap_containsKey(map, NULL));
+ CHECK(hashMap_containsKey(map, key));
+ CHECK(hashMap_containsKey(map, key2));
+ CHECK(!hashMap_containsKey(map, neKey));
+ CHECK(!hashMap_containsKey(map, NULL));
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
- CHECK(hashMap_containsKey(map, key3));
+ CHECK(hashMap_containsKey(map, key3));
- free(neKey);
- hashMap_clear(map, true, true);
+ free(neKey);
+ hashMap_clear(map, true, true);
}
TEST(hash_map, getEntry){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * neKey = my_strdup("notExisting");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- hash_map_entry_pt entry;
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
- entry = hashMap_getEntry(map, key);
- STRCMP_EQUAL(key, (char*) entry->key);
- STRCMP_EQUAL(value, (char*)entry->value);
-
- entry = hashMap_getEntry(map, key2);
- STRCMP_EQUAL(key2, (char*) entry->key);
- STRCMP_EQUAL(value2, (char*) entry->value);
-
- entry = hashMap_getEntry(map, neKey);
- POINTERS_EQUAL(NULL, entry);
-
- entry = hashMap_getEntry(map, NULL);
- POINTERS_EQUAL(NULL, entry);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- entry = hashMap_getEntry(map, key3);
- CHECK_EQUAL(key3, entry->key);
- STRCMP_EQUAL(value3, (char*) entry->value);
-
- free(neKey);
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ hash_map_entry_pt entry;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+ entry = hashMap_getEntry(map, key);
+ STRCMP_EQUAL(key, (char*) entry->key);
+ STRCMP_EQUAL(value, (char*)entry->value);
+
+ entry = hashMap_getEntry(map, key2);
+ STRCMP_EQUAL(key2, (char*) entry->key);
+ STRCMP_EQUAL(value2, (char*) entry->value);
+
+ entry = hashMap_getEntry(map, neKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ entry = hashMap_getEntry(map, NULL);
+ POINTERS_EQUAL(NULL, entry);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key3);
+ CHECK_EQUAL(key3, entry->key);
+ STRCMP_EQUAL(value3, (char*) entry->value);
+
+ free(neKey);
+ hashMap_clear(map, true, true);
}
TEST(hash_map, put){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * nkey2 = my_strdup("key2");
- char * nvalue2 = my_strdup("value3");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * key4 = my_strdup("key4");
- char * value4 = NULL;
- char * old;
- char * get;
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- get = (char*) hashMap_get(map, key);
- STRCMP_EQUAL(value, get);
-
- get = (char*) hashMap_get(map, key2);
- STRCMP_EQUAL(value2, get);
-
- // Try to add an entry with the same key, since no explicit hash function is used,
- // this will not overwrite an existing entry.
- old = (char *) hashMap_put(map, nkey2, nvalue2);
- POINTERS_EQUAL(NULL, old);
-
- // Retrieving the values will return the correct values
- get = (char*) hashMap_get(map, (void*)key2);
- STRCMP_EQUAL(value2, get);
- get = (char*) hashMap_get(map, nkey2);
- STRCMP_EQUAL(nvalue2, get);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- get = (char*) hashMap_get(map, key3);
- STRCMP_EQUAL(value3, get);
-
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
-
- get =(char*)hashMap_get(map, key4);
- CHECK_EQUAL(value4, get);
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * nkey2 = my_strdup("key2");
+ char * nvalue2 = my_strdup("value3");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
+ char * old;
+ char * get;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ get = (char*) hashMap_get(map, key);
+ STRCMP_EQUAL(value, get);
+
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(value2, get);
+
+ // Try to add an entry with the same key, since no explicit hash function is used,
+ // this will not overwrite an existing entry.
+ old = (char *) hashMap_put(map, nkey2, nvalue2);
+ POINTERS_EQUAL(NULL, old);
+
+ // Retrieving the values will return the correct values
+ get = (char*) hashMap_get(map, (void*)key2);
+ STRCMP_EQUAL(value2, get);
+ get = (char*) hashMap_get(map, nkey2);
+ STRCMP_EQUAL(nvalue2, get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ get = (char*) hashMap_get(map, key3);
+ STRCMP_EQUAL(value3, get);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+
+ get =(char*)hashMap_get(map, key4);
+ CHECK_EQUAL(value4, get);
+
+ hashMap_clear(map, true, true);
}
TEST(hash_map, resize){
- int i;
- char key[6];
-
- LONGS_EQUAL(0, map->size);
- LONGS_EQUAL(16, map->tablelength);
- LONGS_EQUAL(12, map->treshold);
- for (i = 0; i < 12; i++) {
- char key[6];
- sprintf(key, "key%d", i);
- hashMap_put(map, my_strdup(key), my_strdup(key));
- }
- LONGS_EQUAL(12, map->size);
- LONGS_EQUAL(16, map->tablelength);
- LONGS_EQUAL(12, map->treshold);
-
- sprintf(key, "key%d", i);
- hashMap_put(map, my_strdup(key), my_strdup(key));
- LONGS_EQUAL(13, map->size);
- LONGS_EQUAL(32, map->tablelength);
- LONGS_EQUAL(24, map->treshold);
-
- hashMap_clear(map, true, true);
+ int i;
+ char key[6];
+
+ LONGS_EQUAL(0, map->size);
+ LONGS_EQUAL(16, map->tablelength);
+ LONGS_EQUAL(12, map->treshold);
+ for (i = 0; i < 12; i++) {
+ char key[6];
+ sprintf(key, "key%d", i);
+ hashMap_put(map, my_strdup(key), my_strdup(key));
+ }
+ LONGS_EQUAL(12, map->size);
+ LONGS_EQUAL(16, map->tablelength);
+ LONGS_EQUAL(12, map->treshold);
+
+ sprintf(key, "key%d", i);
+ hashMap_put(map, my_strdup(key), my_strdup(key));
+ LONGS_EQUAL(13, map->size);
+ LONGS_EQUAL(32, map->tablelength);
+ LONGS_EQUAL(24, map->treshold);
+
+ hashMap_clear(map, true, true);
}
TEST(hash_map, remove){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = NULL;
- char * value2 = my_strdup("value2");
- char * removeKey;
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- // Remove non-existing entry for map
- removeKey = my_strdup("nonexisting");
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(2, map->size);
- CHECK(!hashMap_isEmpty(map));
-
- hashMap_remove(map, key);
- LONGS_EQUAL(1, map->size);
-
- hashMap_remove(map, key2);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
-
- // Remove non-existing entry for empty map
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
-
- free(key);
- free(value);
- free(key2);
- free(value2);
- free(removeKey);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ char * removeKey;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ // Remove non-existing entry for map
+ removeKey = my_strdup("nonexisting");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(2, map->size);
+ CHECK(!hashMap_isEmpty(map));
+
+ hashMap_remove(map, key);
+ LONGS_EQUAL(1, map->size);
+
+ hashMap_remove(map, key2);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ // Remove non-existing entry for empty map
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(removeKey);
}
TEST(hash_map, removeMapping){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = NULL;
- char * value2 = my_strdup("value2");
- hash_map_entry_pt entry1;
- hash_map_entry_pt entry2;
- hash_map_entry_pt removed;
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- entry1 = hashMap_getEntry(map, key);
- entry2 = hashMap_getEntry(map, key2);
-
- CHECK(entry1 != NULL);
- CHECK(entry2 != NULL);
-
- removed = hashMap_removeMapping(map, entry1);
- POINTERS_EQUAL(removed, entry1);
- LONGS_EQUAL(1, map->size);
-
- removed = hashMap_removeMapping(map, entry2);
- POINTERS_EQUAL(removed, entry2);
- LONGS_EQUAL(0, map->size);
-
- // Remove unexisting entry for empty map
- hashMap_removeMapping(map, NULL);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
-
- free(key);
- free(value);
- free(key2);
- free(value2);
- free(entry1);
- free(entry2);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ hash_map_entry_pt entry1;
+ hash_map_entry_pt entry2;
+ hash_map_entry_pt removed;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ entry1 = hashMap_getEntry(map, key);
+ entry2 = hashMap_getEntry(map, key2);
+
+ CHECK(entry1 != NULL);
+ CHECK(entry2 != NULL);
+
+ removed = hashMap_removeMapping(map, entry1);
+ POINTERS_EQUAL(removed, entry1);
+ LONGS_EQUAL(1, map->size);
+
+ removed = hashMap_removeMapping(map, entry2);
+ POINTERS_EQUAL(removed, entry2);
+ LONGS_EQUAL(0, map->size);
+
+ // Remove unexisting entry for empty map
+ hashMap_removeMapping(map, NULL);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(entry1);
+ free(entry2);
}
TEST(hash_map, clear){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * key4 = my_strdup("key4");
- char * value4 = NULL;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
- // Clear but leave keys and values intact
- hashMap_clear(map, false, false);
- LONGS_EQUAL(0, map->size);
+ // Clear but leave keys and values intact
+ hashMap_clear(map, false, false);
+ LONGS_EQUAL(0, map->size);
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
- // Clear and clean up keys and values
- hashMap_clear(map, true, true);
- LONGS_EQUAL(0, map->size);
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+ // Clear and clean up keys and values
+ hashMap_clear(map, true, true);
+ LONGS_EQUAL(0, map->size);
}
TEST(hash_map, containsValue){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * neValue = my_strdup("notExisting");
- char * key3 = my_strdup("key3");
- char * value3 = NULL;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neValue = my_strdup("notExisting");
+ char * key3 = my_strdup("key3");
+ char * value3 = NULL;
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- CHECK(hashMap_containsValue(map, value));
- CHECK(hashMap_containsValue(map, value2));
- CHECK(!hashMap_containsValue(map, neValue));
- CHECK(!hashMap_containsValue(map, NULL));
+ CHECK(hashMap_containsValue(map, value));
+ CHECK(hashMap_containsValue(map, value2));
+ CHECK(!hashMap_containsValue(map, neValue));
+ CHECK(!hashMap_containsValue(map, NULL));
- // Add third entry with NULL value
- hashMap_put(map, key3, value3);
+ // Add third entry with NULL value
+ hashMap_put(map, key3, value3);
- CHECK(hashMap_containsValue(map, value3));
+ CHECK(hashMap_containsValue(map, value3));
- free(neValue);
- hashMap_clear(map, true, true);
+ free(neValue);
+ hashMap_clear(map, true, true);
}
TEST(hash_map, ValuestoArray){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char **array;
- unsigned int size;
- hash_map_values_pt values;
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- values = hashMapValues_create(map);
- hashMapValues_toArray(values, (void***)&array, &size);
- LONGS_EQUAL(2, size);
- CHECK(hashMapValues_contains(values, array[0]));
- CHECK(hashMapValues_contains(values, array[1]));
-
- free(array);
- hashMapValues_destroy(values);
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char **array;
+ unsigned int size;
+ hash_map_values_pt values;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ values = hashMapValues_create(map);
+ hashMapValues_toArray(values, (void***)&array, &size);
+ LONGS_EQUAL(2, size);
+ CHECK(hashMapValues_contains(values, array[0]));
+ CHECK(hashMapValues_contains(values, array[1]));
+
+ free(array);
+ hashMapValues_destroy(values);
+ hashMap_clear(map, true, true);
}
TEST(hash_map, entryGetKey){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * get;
- hash_map_entry_pt entry;
-
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
- hashMap_put(map, key3, value3);
-
- entry = hashMap_getEntry(map, key);
- get = (char*) hashMapEntry_getKey(entry);
- STRCMP_EQUAL(key, get);
-
- entry = hashMap_getEntry(map, key2);
- get = (char*) hashMapEntry_getKey(entry);
- STRCMP_EQUAL(key2, get);
-
- entry = hashMap_getEntry(map, key3);
- get = (char*) hashMapEntry_getKey(entry);
- POINTERS_EQUAL(key3, get);
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
+ hash_map_entry_pt entry;
+
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key);
+ get = (char*) hashMapEntry_getKey(entry);
+ STRCMP_EQUAL(key, get);
+
+ entry = hashMap_getEntry(map, key2);
+ get = (char*) hashMapEntry_getKey(entry);
+ STRCMP_EQUAL(key2, get);
+
+ entry = hashMap_getEntry(map, key3);
+ get = (char*) hashMapEntry_getKey(entry);
+ POINTERS_EQUAL(key3, get);
+
+ hashMap_clear(map, true, true);
}
TEST(hash_map, entryGetValue){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * get;
- hash_map_entry_pt entry;
-
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
- hashMap_put(map, key3, value3);
-
- entry = hashMap_getEntry(map, key);
- get = (char*) hashMapEntry_getValue(entry);
- STRCMP_EQUAL(value, get);
-
- entry = hashMap_getEntry(map, key2);
- get = (char*) hashMapEntry_getValue(entry);
- STRCMP_EQUAL(value2, get);
-
- entry = hashMap_getEntry(map, key3);
- get = (char*) hashMapEntry_getValue(entry);
- POINTERS_EQUAL(value3, get);
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
+ hash_map_entry_pt entry;
+
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key);
+ get = (char*) hashMapEntry_getValue(entry);
+ STRCMP_EQUAL(value, get);
+
+ entry = hashMap_getEntry(map, key2);
+ get = (char*) hashMapEntry_getValue(entry);
+ STRCMP_EQUAL(value2, get);
+
+ entry = hashMap_getEntry(map, key3);
+ get = (char*) hashMapEntry_getValue(entry);
+ POINTERS_EQUAL(value3, get);
+
+ hashMap_clear(map, true, true);
}
//----------------------HASH MAP ITERATOR TEST----------------------
TEST(hash_map_iterator, create){
- it_map = hashMapIterator_create(map);
- CHECK(it_map != NULL);
- POINTERS_EQUAL(map, it_map->map);
- POINTERS_EQUAL(it_map->current, NULL);
- LONGS_EQUAL(map->modificationCount, it_map->expectedModCount);
+ it_map = hashMapIterator_create(map);
+ CHECK(it_map != NULL);
+ POINTERS_EQUAL(map, it_map->map);
+ POINTERS_EQUAL(it_map->current, NULL);
+ LONGS_EQUAL(map->modificationCount, it_map->expectedModCount);
- hashMapIterator_destroy(it_map);
+ hashMapIterator_destroy(it_map);
}
TEST(hash_map_iterator, hasNext){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * key3 = my_strdup("key3");
- char * value3 = my_strdup("value3");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = my_strdup("key3");
+ char * value3 = my_strdup("value3");
- // Add one entry
- hashMap_put(map, key, value);
+ // Add one entry
+ hashMap_put(map, key, value);
- // Add second entry
- hashMap_put(map, key2, value2);
+ // Add second entry
+ hashMap_put(map, key2, value2);
- // Add third entry
- hashMap_put(map, key3, value3);
+ // Add third entry
+ hashMap_put(map, key3, value3);
- //create it_map from map
- it_map = hashMapIterator_create(map);
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
- //check hasNext
- CHECK(hashMapIterator_hasNext(it_map));
+ //check hasNext
+ CHECK(hashMapIterator_hasNext(it_map));
- hashMapIterator_nextEntry(it_map);
- CHECK(hashMapIterator_hasNext(it_map));
+ hashMapIterator_nextEntry(it_map);
+ CHECK(hashMapIterator_hasNext(it_map));
- hashMapIterator_nextEntry(it_map);
- CHECK(hashMapIterator_hasNext(it_map));
+ hashMapIterator_nextEntry(it_map);
+ CHECK(hashMapIterator_hasNext(it_map));
- //third entry next points to NULL
- hashMapIterator_nextEntry(it_map);
- CHECK(!hashMapIterator_hasNext(it_map));
+ //third entry next points to NULL
+ hashMapIterator_nextEntry(it_map);
+ CHECK(!hashMapIterator_hasNext(it_map));
- hashMapIterator_destroy(it_map);
- hashMap_clear(map, true, true);
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_iterator, remove){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * key3 = my_strdup("key3");
- char * value3 = my_strdup("value3");
-
- // Add 3 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
- hashMap_put(map, key3, value3);
-
- //create it_map from map
- it_map = hashMapIterator_create(map);
-
- //try to remove current (NULL)
- hashMapIterator_remove(it_map);
- LONGS_EQUAL(3, map->size);
-
- //delete the first and second entry
- hashMapIterator_nextEntry(it_map);
- hashMapIterator_remove(it_map);
- hashMapIterator_nextEntry(it_map);
- hashMapIterator_remove(it_map);
- LONGS_EQUAL(1, map->size);
-
- free(key);
- free(value);
- free(key2);
- free(value2);
- free(key3);
- free(value3);
- hashMapIterator_destroy(it_map);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = my_strdup("key3");
+ char * value3 = my_strdup("value3");
+
+ // Add 3 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ //try to remove current (NULL)
+ hashMapIterator_remove(it_map);
+ LONGS_EQUAL(3, map->size);
+
+ //delete the first and second entry
+ hashMapIterator_nextEntry(it_map);
+ hashMapIterator_remove(it_map);
+ hashMapIterator_nextEntry(it_map);
+ hashMapIterator_remove(it_map);
+ LONGS_EQUAL(1, map->size);
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(key3);
+ free(value3);
+ hashMapIterator_destroy(it_map);
}
TEST(hash_map_iterator, nextValue){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getValue;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getValue;
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create it_map from map
- it_map = hashMapIterator_create(map);
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
- getValue = (char*) hashMapIterator_nextValue(it_map);
- CHECK(hashMap_containsValue(map, getValue));
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ CHECK(hashMap_containsValue(map, getValue));
- getValue = (char*) hashMapIterator_nextValue(it_map);
- CHECK(hashMap_containsValue(map, getValue));
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ CHECK(hashMap_containsValue(map, getValue));
- getValue = (char*) hashMapIterator_nextValue(it_map);
- POINTERS_EQUAL(NULL, getValue);
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ POINTERS_EQUAL(NULL, getValue);
- hashMapIterator_destroy(it_map);
- hashMap_clear(map, true, true);
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_iterator, nextKey){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getKey;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey;
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create it_map from map
- it_map = hashMapIterator_create(map);
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
- getKey = (char*) hashMapIterator_nextKey(it_map);
- CHECK(hashMap_containsKey(map, getKey));
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ CHECK(hashMap_containsKey(map, getKey));
- getKey = (char*) hashMapIterator_nextKey(it_map);
- CHECK(hashMap_containsKey(map, getKey));
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ CHECK(hashMap_containsKey(map, getKey));
- getKey = (char*) hashMapIterator_nextKey(it_map);
- POINTERS_EQUAL(NULL, getKey);
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ POINTERS_EQUAL(NULL, getKey);
- hashMapIterator_destroy(it_map);
- hashMap_clear(map, true, true);
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_iterator, nextEntry){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getValue;
- hash_map_entry_pt get;
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getValue;
+ hash_map_entry_pt get;
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create it_map from map
- it_map = hashMapIterator_create(map);
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
- get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
- getValue = (char*) hashMap_get(map, get->key);
- STRCMP_EQUAL((char*)get->value, (char*)getValue);
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ getValue = (char*) hashMap_get(map, get->key);
+ STRCMP_EQUAL((char*)get->value, (char*)getValue);
- get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
- getValue = (char*) hashMap_get(map, get->key);
- STRCMP_EQUAL((char*)get->value, (char*)getValue);
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ getValue = (char*) hashMap_get(map, get->key);
+ STRCMP_EQUAL((char*)get->value, (char*)getValue);
- get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
- POINTERS_EQUAL(NULL, get);
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ POINTERS_EQUAL(NULL, get);
- hashMapIterator_destroy(it_map);
- hashMap_clear(map, true, true);
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_iterator, valuesIterator){
- hash_map_values_pt values;
- hash_map_iterator_pt it_val;
+ hash_map_values_pt values;
+ hash_map_iterator_pt it_val;
- values = hashMapValues_create(map);
- it_val = hashMapValues_iterator(values);
+ values = hashMapValues_create(map);
+ it_val = hashMapValues_iterator(values);
- POINTERS_EQUAL(map, it_val->map);
+ POINTERS_EQUAL(map, it_val->map);
- hashMapIterator_destroy(it_val);
- hashMapValues_destroy(values);
+ hashMapIterator_destroy(it_val);
+ hashMapValues_destroy(values);
}
//----------------------HASH MAP VALUES TEST----------------------
TEST(hash_map_values, create){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create Values from map
- values = hashMapValues_create(map);
+ //create Values from map
+ values = hashMapValues_create(map);
- CHECK(hashMapValues_contains(values, value));
- CHECK(hashMapValues_contains(values, value2));
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
- hashMap_clear(map, true, true);
- hashMapValues_destroy(values);
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
}
TEST(hash_map_values, size){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create Values from map
- values = hashMapValues_create(map);
+ //create Values from map
+ values = hashMapValues_create(map);
- LONGS_EQUAL(2, hashMapValues_size(values));
+ LONGS_EQUAL(2, hashMapValues_size(values));
- hashMap_clear(map, true, true);
- hashMapValues_destroy(values);
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
}
TEST(hash_map_values, remove){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
-
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
-
- //create Values from map
- values = hashMapValues_create(map);
- CHECK(hashMapValues_contains(values, value));
- CHECK(hashMapValues_contains(values, value2));
-
- hashMapValues_remove(values, value);
- CHECK(!hashMapValues_contains(values, value));
- CHECK(hashMapValues_contains(values, value2));
-
- hashMapValues_remove(values, value2);
- CHECK(!hashMapValues_contains(values, value));
- CHECK(!hashMapValues_contains(values, value2));
-
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMap_clear(map, true, true);
- hashMapValues_destroy(values);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+
+ hashMapValues_remove(values, value);
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+
+ hashMapValues_remove(values, value2);
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(!hashMapValues_contains(values, value2));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
}
TEST(hash_map_values, clear){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create Values from map
- values = hashMapValues_create(map);
+ //create Values from map
+ values = hashMapValues_create(map);
- CHECK(hashMapValues_contains(values, value));
- CHECK(hashMapValues_contains(values, value2));
- LONGS_EQUAL(2, values->map->size);
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+ LONGS_EQUAL(2, values->map->size);
- hashMapValues_clear(values);
+ hashMapValues_clear(values);
- CHECK(!hashMapValues_contains(values, value));
- CHECK(!hashMapValues_contains(values, value2));
- LONGS_EQUAL(0, values->map->size);
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(!hashMapValues_contains(values, value2));
+ LONGS_EQUAL(0, values->map->size);
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMapValues_destroy(values);
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapValues_destroy(values);
}
TEST(hash_map_values, isEmpty){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- //create Values from map
- values = hashMapValues_create(map);
+ //create Values from map
+ values = hashMapValues_create(map);
- CHECK(!hashMapValues_isEmpty(values));
+ CHECK(!hashMapValues_isEmpty(values));
- hashMapValues_clear(values);
+ hashMapValues_clear(values);
- CHECK(hashMapValues_isEmpty(values));
+ CHECK(hashMapValues_isEmpty(values));
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMapValues_destroy(values);
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapValues_destroy(values);
}
//----------------------HASH MAP KEYSET TEST----------------------
TEST(hash_map_keySet, create){
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- POINTERS_EQUAL(map, key_set->map);
+ POINTERS_EQUAL(map, key_set->map);
- hashMapKeySet_destroy(key_set);
+ hashMapKeySet_destroy(key_set);
}
TEST(hash_map_keySet, size){
- char * key = my_strdup("key");
- char * key2 = my_strdup("key2");
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- LONGS_EQUAL(0, hashMapKeySet_size(key_set));
+ LONGS_EQUAL(0, hashMapKeySet_size(key_set));
- // Add 2 entries
- hashMap_put(map, key, NULL);
- hashMap_put(map, key2, NULL);
+ // Add 2 entries
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
- LONGS_EQUAL(2, hashMapKeySet_size(key_set));
+ LONGS_EQUAL(2, hashMapKeySet_size(key_set));
- hashMap_clear(map, true, true);
- hashMapKeySet_destroy(key_set);
+ hashMap_clear(map, true, true);
+ hashMapKeySet_destroy(key_set);
}
TEST(hash_map_keySet, contains){
- char * key = my_strdup("key");
- char * key2 = my_strdup("key2");
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- CHECK(!hashMapKeySet_contains(key_set, key));
- CHECK(!hashMapKeySet_contains(key_set, key2));
+ CHECK(!hashMapKeySet_contains(key_set, key));
+ CHECK(!hashMapKeySet_contains(key_set, key2));
- // Add 2 entries
- hashMap_put(map, key, NULL);
+ // Add 2 entries
+ hashMap_put(map, key, NULL);
- CHECK(hashMapKeySet_contains(key_set, key));
- CHECK(!hashMapKeySet_contains(key_set, key2));
+ CHECK(hashMapKeySet_contains(key_set, key));
+ CHECK(!hashMapKeySet_contains(key_set, key2));
- hashMap_put(map, key2, NULL);
+ hashMap_put(map, key2, NULL);
- CHECK(hashMapKeySet_contains(key_set, key));
- CHECK(hashMapKeySet_contains(key_set, key2));
+ CHECK(hashMapKeySet_contains(key_set, key));
+ CHECK(hashMapKeySet_contains(key_set, key2));
- hashMap_clear(map, true, true);
- hashMapKeySet_destroy(key_set);
+ hashMap_clear(map, true, true);
+ hashMapKeySet_destroy(key_set);
}
TEST(hash_map_keySet, remove){
- char * key = my_strdup("key");
- char * key2 = my_strdup("key2");
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- // Add 2 entries
- hashMap_put(map, key, NULL);
- hashMap_put(map, key2, NULL);
+ // Add 2 entries
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
- LONGS_EQUAL(2, key_set->map->size);
+ LONGS_EQUAL(2, key_set->map->size);
- hashMapKeySet_remove(key_set, key);
+ hashMapKeySet_remove(key_set, key);
- LONGS_EQUAL(1, key_set->map->size);
+ LONGS_EQUAL(1, key_set->map->size);
- hashMapKeySet_remove(key_set, key2);
+ hashMapKeySet_remove(key_set, key2);
- LONGS_EQUAL(0, key_set->map->size);
+ LONGS_EQUAL(0, key_set->map->size);
- free(key);
- free(key2);
- hashMapKeySet_destroy(key_set);
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
}
TEST(hash_map_keySet, clear){
- char * key = my_strdup("key");
- char * key2 = my_strdup("key2");
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- // Add 2 entries
- hashMap_put(map, key, NULL);
- hashMap_put(map, key2, NULL);
+ // Add 2 entries
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
- LONGS_EQUAL(2, key_set->map->size);
+ LONGS_EQUAL(2, key_set->map->size);
- hashMapKeySet_clear(key_set);
+ hashMapKeySet_clear(key_set);
- LONGS_EQUAL(0, key_set->map->size);
+ LONGS_EQUAL(0, key_set->map->size);
- free(key);
- free(key2);
- hashMapKeySet_destroy(key_set);
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
}
TEST(hash_map_keySet, isEmpty){
- char * key = my_strdup("key");
- char * key2 = my_strdup("key2");
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
- key_set = hashMapKeySet_create(map);
+ key_set = hashMapKeySet_create(map);
- CHECK(hashMapKeySet_isEmpty(key_set));
+ CHECK(hashMapKeySet_isEmpty(key_set));
- // Add 2 entries
- hashMap_put(map, key, NULL);
- hashMap_put(map, key2, NULL);
+ // Add 2 entries
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
- CHECK(!hashMapKeySet_isEmpty(key_set));
+ CHECK(!hashMapKeySet_isEmpty(key_set));
- hashMapKeySet_clear(key_set);
+ hashMapKeySet_clear(key_set);
- CHECK(hashMapKeySet_isEmpty(key_set));
+ CHECK(hashMapKeySet_isEmpty(key_set));
- free(key);
- free(key2);
- hashMapKeySet_destroy(key_set);
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
}
//----------------------HASH MAP ENTRYSET TEST----------------------
TEST(hash_map_entrySet, create){
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- POINTERS_EQUAL(map, entry_set->map);
+ POINTERS_EQUAL(map, entry_set->map);
- hashMapEntrySet_destroy(entry_set);
+ hashMapEntrySet_destroy(entry_set);
}
TEST(hash_map_entrySet, size){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- LONGS_EQUAL(0, hashMapEntrySet_size(entry_set));
+ LONGS_EQUAL(0, hashMapEntrySet_size(entry_set));
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- LONGS_EQUAL(2, hashMapEntrySet_size(entry_set));
+ LONGS_EQUAL(2, hashMapEntrySet_size(entry_set));
- hashMap_clear(map, true, true);
- hashMapEntrySet_destroy(entry_set);
+ hashMap_clear(map, true, true);
+ hashMapEntrySet_destroy(entry_set);
}
TEST(hash_map_entrySet, contains){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- CHECK(!hashMapEntrySet_contains(entry_set, NULL));
- CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key)));
- CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key2)));
+ CHECK(!hashMapEntrySet_contains(entry_set, NULL));
+ CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key)));
+ CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key2)));
- hashMap_clear(map, true, true);
- hashMapEntrySet_destroy(entry_set);
+ hashMap_clear(map, true, true);
+ hashMapEntrySet_destroy(entry_set);
}
TEST(hash_map_entrySet, remove){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- CHECK(!hashMapEntrySet_remove(entry_set, (hash_map_entry_pt) NULL));
- LONGS_EQUAL(2, entry_set->map->size);
+ CHECK(!hashMapEntrySet_remove(entry_set, (hash_map_entry_pt) NULL));
+ LONGS_EQUAL(2, entry_set->map->size);
- CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key)));
- LONGS_EQUAL(1, entry_set->map->size);
+ CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key)));
+ LONGS_EQUAL(1, entry_set->map->size);
- CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key2)));
- LONGS_EQUAL(0, entry_set->map->size);
+ CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key2)));
+ LONGS_EQUAL(0, entry_set->map->size);
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMap_clear(map, false, false);
- hashMapEntrySet_destroy(entry_set);
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMap_clear(map, false, false);
+ hashMapEntrySet_destroy(entry_set);
}
TEST(hash_map_entrySet, clear){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- LONGS_EQUAL(2, entry_set->map->size);
+ LONGS_EQUAL(2, entry_set->map->size);
- hashMapEntrySet_clear(entry_set);
+ hashMapEntrySet_clear(entry_set);
- LONGS_EQUAL(0, entry_set->map->size);
+ LONGS_EQUAL(0, entry_set->map->size);
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMapEntrySet_destroy(entry_set);
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapEntrySet_destroy(entry_set);
}
TEST(hash_map_entrySet, isEmpty){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
- entry_set = hashMapEntrySet_create(map);
+ entry_set = hashMapEntrySet_create(map);
- CHECK(hashMapEntrySet_isEmpty(entry_set));
+ CHECK(hashMapEntrySet_isEmpty(entry_set));
- // Add 2 entries
- hashMap_put(map, key, value);
- hashMap_put(map, key2, value2);
+ // Add 2 entries
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
- CHECK(!hashMapEntrySet_isEmpty(entry_set));
+ CHECK(!hashMapEntrySet_isEmpty(entry_set));
- hashMapEntrySet_clear(entry_set);
+ hashMapEntrySet_clear(entry_set);
- CHECK(hashMapEntrySet_isEmpty(entry_set));
+ CHECK(hashMapEntrySet_isEmpty(entry_set));
- free(key);
- free(value);
- free(key2);
- free(value2);
- hashMapEntrySet_destroy(entry_set);
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapEntrySet_destroy(entry_set);
}
//----------------------HASH MAP HASH TEST----------------------
TEST(hash_map_hash, get){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getKey = my_strdup("key");
- char * get;
- char * neKey = my_strdup("notExisting");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new created key
- get = (char*) (char*) hashMap_get(map, getKey);
- CHECK_C(get != NULL);
- STRCMP_EQUAL(value, get);
-
- free(getKey);
- getKey = my_strdup("key2");
- get = (char*) hashMap_get(map, getKey);
- CHECK_C(get != NULL);
- STRCMP_EQUAL(value2, get);
-
- get = (char*) hashMap_get(map, neKey);
- POINTERS_EQUAL(NULL, get);
-
- get = (char*) hashMap_get(map, NULL);
- POINTERS_EQUAL(NULL,get);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- get = (char*) hashMap_get(map, NULL);
- STRCMP_EQUAL(get, value3);
-
- free(getKey);
- free(neKey);
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey = my_strdup("key");
+ char * get;
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new created key
+ get = (char*) (char*) hashMap_get(map, getKey);
+ CHECK_C(get != NULL);
+ STRCMP_EQUAL(value, get);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, getKey);
+ CHECK_C(get != NULL);
+ STRCMP_EQUAL(value2, get);
+
+ get = (char*) hashMap_get(map, neKey);
+ POINTERS_EQUAL(NULL, get);
+
+ get = (char*) hashMap_get(map, NULL);
+ POINTERS_EQUAL(NULL,get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ get = (char*) hashMap_get(map, NULL);
+ STRCMP_EQUAL(get, value3);
+
+ free(getKey);
+ free(neKey);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_hash, containsKey) {
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * containsKey = my_strdup("key");
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- CHECK(hashMap_containsKey(map, containsKey));
- free(containsKey);
- containsKey = my_strdup("key2");
- CHECK(hashMap_containsKey(map, containsKey));
- free(containsKey);
- containsKey = my_strdup("notExisting");
- CHECK(!hashMap_containsKey(map, containsKey));
- free(containsKey);
- containsKey = NULL;
- CHECK(!hashMap_containsKey(map, containsKey));
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- containsKey = NULL;
- CHECK(hashMap_containsKey(map, containsKey));
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * containsKey = my_strdup("key");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = my_strdup("key2");
+ CHECK(hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = my_strdup("notExisting");
+ CHECK(!hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = NULL;
+ CHECK(!hashMap_containsKey(map, containsKey));
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ containsKey = NULL;
+ CHECK(hashMap_containsKey(map, containsKey));
+
+ hashMap_clear(map, true, true);
}
TEST(hash_map_hash, getEntry){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getEntryKey;
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- hash_map_entry_pt entry;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new created key
- getEntryKey = my_strdup("key");
- entry = hashMap_getEntry(map, getEntryKey);
- CHECK(entry != NULL);
- STRCMP_EQUAL(key, (char*) entry->key);
- STRCMP_EQUAL(value, (char*) entry->value);
-
- free(getEntryKey);
- getEntryKey = my_strdup("key2");
- entry = hashMap_getEntry(map, getEntryKey);
- CHECK(entry != NULL);
- STRCMP_EQUAL(key2, (char*) entry->key);
- STRCMP_EQUAL(value2, (char*) entry->value);
-
- free(getEntryKey);
- getEntryKey = my_strdup("notExisting");
- entry = hashMap_getEntry(map, getEntryKey);
- POINTERS_EQUAL(NULL, entry);
-
- free(getEntryKey);
- getEntryKey = NULL;
- entry = hashMap_getEntry(map, getEntryKey);
- POINTERS_EQUAL(NULL, entry);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- getEntryKey = NULL;
- entry = hashMap_getEntry(map, getEntryKey);
- CHECK_EQUAL(key3, entry->key);
- STRCMP_EQUAL(value3, (char*) entry->value);
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getEntryKey;
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ hash_map_entry_pt entry;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new created key
+ getEntryKey = my_strdup("key");
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK(entry != NULL);
+ STRCMP_EQUAL(key, (char*) entry->key);
+ STRCMP_EQUAL(value, (char*) entry->value);
+
+ free(getEntryKey);
+ getEntryKey = my_strdup("key2");
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK(entry != NULL);
+ STRCMP_EQUAL(key2, (char*) entry->key);
+ STRCMP_EQUAL(value2, (char*) entry->value);
+
+ free(getEntryKey);
+ getEntryKey = my_strdup("notExisting");
+ entry = hashMap_getEntry(map, getEntryKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ free(getEntryKey);
+ getEntryKey = NULL;
+ entry = hashMap_getEntry(map, getEntryKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ getEntryKey = NULL;
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK_EQUAL(key3, entry->key);
+ STRCMP_EQUAL(value3, (char*) entry->value);
+
+ hashMap_clear(map, true, true);
}
TEST(hash_map_hash, put){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * getKey = my_strdup("key");
- char * get;
- char * nkey2 = my_strdup("key2");
- char * nvalue2 = my_strdup("value3");
- char * old;
- char * key3 = NULL;
- char * value3 = my_strdup("value3");
- char * key4 = my_strdup("key4");
- char * value4 = NULL;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new key
- get = (char*) hashMap_get(map, getKey);
- STRCMP_EQUAL(value, get);
-
- free(getKey);
- getKey = my_strdup("key2");
- get = (char*) hashMap_get(map, getKey);
- STRCMP_EQUAL(value2, get);
-
- // Overwrite existing entry
- old = (char *) hashMap_put(map, nkey2, nvalue2);
- CHECK(old != NULL);
- STRCMP_EQUAL(value2, old);
-
- free(getKey);
- getKey = my_strdup("key2");
- get = (char*) hashMap_get(map, key2);
- STRCMP_EQUAL(nvalue2, get);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- free(getKey);
- getKey = NULL;
- get = (char*) hashMap_get(map, key3);
- STRCMP_EQUAL(value3, get);
-
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
-
- getKey = my_strdup("key4");
- get = (char*) hashMap_get(map, key4);
- CHECK_EQUAL(value4, get);
-
- free(getKey);
- free(value2);
- free(nkey2);
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey = my_strdup("key");
+ char * get;
+ char * nkey2 = my_strdup("key2");
+ char * nvalue2 = my_strdup("value3");
+ char * old;
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new key
+ get = (char*) hashMap_get(map, getKey);
+ STRCMP_EQUAL(value, get);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, getKey);
+ STRCMP_EQUAL(value2, get);
+
+ // Overwrite existing entry
+ old = (char *) hashMap_put(map, nkey2, nvalue2);
+ CHECK(old != NULL);
+ STRCMP_EQUAL(value2, old);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(nvalue2, get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ free(getKey);
+ getKey = NULL;
+ get = (char*) hashMap_get(map, key3);
+ STRCMP_EQUAL(value3, get);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+
+ getKey = my_strdup("key4");
+ get = (char*) hashMap_get(map, key4);
+ CHECK_EQUAL(value4, get);
+
+ free(getKey);
+ free(value2);
+ free(nkey2);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_hash, remove){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = NULL;
- char * value2 = my_strdup("value2");
- char * removeKey = my_strdup("nonexisting");
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- // Remove non-existing entry for map
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(2, map->size);
- CHECK(!hashMap_isEmpty(map));
-
- // Remove entry with new key
- free(removeKey);
- removeKey = my_strdup("key");
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(1, map->size);
-
- free(removeKey);
- removeKey = NULL;
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
-
- // Remove non-existing entry for empty map
- removeKey = my_strdup("nonexisting");
- hashMap_remove(map, removeKey);
- LONGS_EQUAL(0, map->size);
- CHECK(hashMap_isEmpty(map));
-
- free(removeKey);
- free(key);
- free(value);
- free(value2);
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ char * removeKey = my_strdup("nonexisting");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ // Remove non-existing entry for map
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(2, map->size);
+ CHECK(!hashMap_isEmpty(map));
+
+ // Remove entry with new key
+ free(removeKey);
+ removeKey = my_strdup("key");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(1, map->size);
+
+ free(removeKey);
+ removeKey = NULL;
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ // Remove non-existing entry for empty map
+ removeKey = my_strdup("nonexisting");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(removeKey);
+ free(key);
+ free(value);
+ free(value2);
+ hashMap_clear(map, true, true);
}
TEST(hash_map_hash, containsValue){
- char * key = my_strdup("key");
- char * value = my_strdup("value");
- char * key2 = my_strdup("key2");
- char * value2 = my_strdup("value2");
- char * containsValue = my_strdup("value");
- char * key3 = my_strdup("key3");
- char * value3 = NULL;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- CHECK(hashMap_containsValue(map, containsValue));
- free(containsValue);
- containsValue = my_strdup("value2");
- CHECK(hashMap_containsValue(map, containsValue));
- free(containsValue);
- containsValue = my_strdup("notExisting");
- CHECK(!hashMap_containsValue(map, containsValue));
- free(containsValue);
- containsValue = NULL;
- CHECK(!hashMap_containsValue(map, containsValue));
-
- // Add third entry with NULL value
- hashMap_put(map, key3, value3);
-
- containsValue = NULL;
- CHECK(hashMap_containsValue(map, containsValue));
-
- hashMap_clear(map, true, true);
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * containsValue = my_strdup("value");
+ char * key3 = my_strdup("key3");
+ char * value3 = NULL;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = my_strdup("value2");
+ CHECK(hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = my_strdup("notExisting");
+ CHECK(!hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = NULL;
+ CHECK(!hashMap_containsValue(map, containsValue));
+
+ // Add third entry with NULL value
+ hashMap_put(map, key3, value3);
+
+ containsValue = NULL;
+ CHECK(hashMap_containsValue(map, containsValue));
+
+ hashMap_clear(map, true, true);
}
diff --git a/libs/utils/private/test/ip_utils_test.cpp b/libs/utils/private/test/ip_utils_test.cpp
index 0a2629d..a7854b5 100644
--- a/libs/utils/private/test/ip_utils_test.cpp
+++ b/libs/utils/private/test/ip_utils_test.cpp
@@ -38,7 +38,7 @@ extern "C"
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s){
@@ -59,17 +59,17 @@ static char* my_strdup(const char* s){
}
TEST_GROUP(ip_utils) {
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown() {
- }
+ void teardown() {
+ }
};
TEST(ip_utils, ipToUnsignedInt){
- char *ip = my_strdup("192.168.1.64");
+ char *ip = my_strdup("192.168.1.64");
- unsigned int expected = 3232235840;
+ unsigned int expected = 3232235840;
unsigned int actual = ipUtils_ipToUnsignedInt(ip);
UNSIGNED_LONGS_EQUAL(expected, actual);
diff --git a/libs/utils/private/test/linked_list_test.cpp b/libs/utils/private/test/linked_list_test.cpp
index 1df971b..059290e 100644
--- a/libs/utils/private/test/linked_list_test.cpp
+++ b/libs/utils/private/test/linked_list_test.cpp
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* linked_list_test.cpp
*
- * \date Sep 15, 2015
- * \author Menno van der Graaf
- * \copyright Apache License, Version 2.0
+ * \date Sep 15, 2015
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
+
#include <stdio.h>
#include <stddef.h>
#include <string.h>
@@ -39,756 +40,756 @@ extern "C"
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s){
- char *d = (char*) malloc (strlen (s) + 1);
- if (d == NULL) return NULL;
- strcpy (d,s);
- return d;
+ char *d = (char*) malloc (strlen (s) + 1);
+ if (d == NULL) return NULL;
+ strcpy (d,s);
+ return d;
}
//----------------------TESTGROUP DEFINES----------------------
TEST_GROUP(linked_list){
- linked_list_pt list;
+ linked_list_pt list;
- void setup(void) {
- linkedList_create(&list);
- }
+ void setup(void) {
+ linkedList_create(&list);
+ }
- void teardown(void) {
- linkedList_destroy(list);
- }
+ void teardown(void) {
+ linkedList_destroy(list);
+ }
};
TEST_GROUP(linked_list_iterator){
- linked_list_pt list;
+ linked_list_pt list;
- void setup(void) {
- linkedList_create(&list);
- }
+ void setup(void) {
+ linkedList_create(&list);
+ }
- void teardown(void) {
- linkedList_destroy(list);
- }
+ void teardown(void) {
+ linkedList_destroy(list);
+ }
};
//----------------------LINKED LIST TESTS----------------------
TEST(linked_list, create){
- CHECK(list != NULL);
- LONGS_EQUAL(0, linkedList_size(list));
+ CHECK(list != NULL);
+ LONGS_EQUAL(0, linkedList_size(list));
}
TEST(linked_list, add){
- char * value = my_strdup("element");
+ char * value = my_strdup("element");
- LONGS_EQUAL(0, linkedList_size(list));
- linkedList_addElement(list, value);
- LONGS_EQUAL(1, linkedList_size(list));
+ LONGS_EQUAL(0, linkedList_size(list));
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(1, linkedList_size(list));
- free(value);
+ free(value);
}
TEST(linked_list, addFirst){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
- STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
- linkedList_addFirst(list, value3);
+ linkedList_addFirst(list, value3);
- STRCMP_EQUAL(value3, (char*) linkedList_getFirst(list));
+ STRCMP_EQUAL(value3, (char*) linkedList_getFirst(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, addLast){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
- STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
+ STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
- linkedList_addLast(list, value3);
+ linkedList_addLast(list, value3);
- STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, addIndex){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- char * value4 = my_strdup("element4");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- linkedList_addIndex(list, 2, value4);
+ linkedList_addIndex(list, 2, value4);
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
- free(value);
- free(value2);
- free(value3);
- free(value4);
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
}
TEST(linked_list, addBefore){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- char * value4 = my_strdup("element4");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- linkedList_addBefore(list, value4, linkedList_entry(list, 2));
+ linkedList_addBefore(list, value4, linkedList_entry(list, 2));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
- free(value);
- free(value2);
- free(value3);
- free(value4);
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
}
TEST(linked_list, remove){
- char * value = strdup("element");
+ char * value = strdup("element");
- LONGS_EQUAL(0, linkedList_size(list));
- linkedList_addElement(list, value);
- LONGS_EQUAL(1, linkedList_size(list));
+ LONGS_EQUAL(0, linkedList_size(list));
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(1, linkedList_size(list));
- linkedList_removeElement(list, value);
- LONGS_EQUAL(0, linkedList_size(list));
+ linkedList_removeElement(list, value);
+ LONGS_EQUAL(0, linkedList_size(list));
- free(value);
+ free(value);
}
TEST(linked_list, removeFirst){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
- linkedList_removeFirst(list);
+ linkedList_removeFirst(list);
- STRCMP_EQUAL(value2, (char*) linkedList_getFirst(list));
+ STRCMP_EQUAL(value2, (char*) linkedList_getFirst(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, removeLast){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
- linkedList_removeLast(list);
+ linkedList_removeLast(list);
- STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
+ STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, removeElement){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- //add 6 elements
- linkedList_addElement(list, NULL);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, NULL);
- linkedList_addElement(list, value3);
- LONGS_EQUAL(6, list->size);
+ //add 6 elements
+ linkedList_addElement(list, NULL);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, NULL);
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(6, list->size);
- linkedList_removeElement(list, NULL);
- linkedList_removeElement(list, NULL);
- LONGS_EQUAL(4, list->size);
+ linkedList_removeElement(list, NULL);
+ linkedList_removeElement(list, NULL);
+ LONGS_EQUAL(4, list->size);
- linkedList_removeElement(list, value2);
- LONGS_EQUAL(3, list->size);
+ linkedList_removeElement(list, value2);
+ LONGS_EQUAL(3, list->size);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, removeIndex){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- linkedList_removeIndex(list, 1);
+ linkedList_removeIndex(list, 1);
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, removeEntry){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- linkedList_removeEntry(list, list->header);
- LONGS_EQUAL(3, list->size);
+ linkedList_removeEntry(list, list->header);
+ LONGS_EQUAL(3, list->size);
- linkedList_removeEntry(list, linkedList_entry(list, 0));
- LONGS_EQUAL(2, list->size);
+ linkedList_removeEntry(list, linkedList_entry(list, 0));
+ LONGS_EQUAL(2, list->size);
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, clone){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_pt list2;
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_pt list2;
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- linkedList_clone(list, &list2);
- LONGS_EQUAL(list->size, list2->size);
- STRCMP_EQUAL( (char*) linkedList_getFirst(list), (char*) linkedList_getFirst(list2));
- STRCMP_EQUAL( (char*) linkedList_getLast(list), (char*) linkedList_getLast(list2));
+ linkedList_clone(list, &list2);
+ LONGS_EQUAL(list->size, list2->size);
+ STRCMP_EQUAL( (char*) linkedList_getFirst(list), (char*) linkedList_getFirst(list2));
+ STRCMP_EQUAL( (char*) linkedList_getLast(list), (char*) linkedList_getLast(list2));
- free(value);
- free(value2);
- free(value3);
- linkedList_destroy(list2);
+ free(value);
+ free(value2);
+ free(value3);
+ linkedList_destroy(list2);
}
TEST(linked_list, clear){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- LONGS_EQUAL(3, list->size);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(3, list->size);
- linkedList_clear(list);
- LONGS_EQUAL(0, list->size);
+ linkedList_clear(list);
+ LONGS_EQUAL(0, list->size);
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, get){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, getFirst){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, getLast){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, set){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- linkedList_set(list, 1, value3);
+ linkedList_set(list, 1, value3);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, contains){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- linkedList_addElement(list, value);
- CHECK(linkedList_contains(list, value));
- CHECK(!linkedList_contains(list, value2));
- CHECK(!linkedList_contains(list, value3));
+ linkedList_addElement(list, value);
+ CHECK(linkedList_contains(list, value));
+ CHECK(!linkedList_contains(list, value2));
+ CHECK(!linkedList_contains(list, value3));
- linkedList_addElement(list, value2);
- CHECK(linkedList_contains(list, value));
- CHECK(linkedList_contains(list, value2));
- CHECK(!linkedList_contains(list, value3));
+ linkedList_addElement(list, value2);
+ CHECK(linkedList_contains(list, value));
+ CHECK(linkedList_contains(list, value2));
+ CHECK(!linkedList_contains(list, value3));
- linkedList_addElement(list, value3);
- CHECK(linkedList_contains(list, value));
- CHECK(linkedList_contains(list, value2));
- CHECK(linkedList_contains(list, value3));
+ linkedList_addElement(list, value3);
+ CHECK(linkedList_contains(list, value));
+ CHECK(linkedList_contains(list, value2));
+ CHECK(linkedList_contains(list, value3));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, size){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- LONGS_EQUAL(0, linkedList_size(list));
+ LONGS_EQUAL(0, linkedList_size(list));
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- LONGS_EQUAL(3, linkedList_size(list));
+ LONGS_EQUAL(3, linkedList_size(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, isEmpty){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- CHECK(linkedList_isEmpty(list));
+ CHECK(linkedList_isEmpty(list));
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- CHECK(!linkedList_isEmpty(list));
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ CHECK(!linkedList_isEmpty(list));
- linkedList_clear(list);
- CHECK(linkedList_isEmpty(list));
+ linkedList_clear(list);
+ CHECK(linkedList_isEmpty(list));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
TEST(linked_list, entry){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- char * value4 = my_strdup("element4");
- char * value5 = my_strdup("element5");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
+ char * value5 = my_strdup("element5");
- POINTERS_EQUAL(NULL, linkedList_entry(list, 666));
+ POINTERS_EQUAL(NULL, linkedList_entry(list, 666));
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- linkedList_addElement(list, value4);
- linkedList_addElement(list, value5);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ linkedList_addElement(list, value4);
+ linkedList_addElement(list, value5);
- STRCMP_EQUAL(value2, (char*) linkedList_entry(list, 1)->element);
- STRCMP_EQUAL(value4, (char*) linkedList_entry(list, 3)->element);
+ STRCMP_EQUAL(value2, (char*) linkedList_entry(list, 1)->element);
+ STRCMP_EQUAL(value4, (char*) linkedList_entry(list, 3)->element);
- free(value);
- free(value2);
- free(value3);
- free(value4);
- free(value5);
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
+ free(value5);
}
TEST(linked_list, indexOf){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
- LONGS_EQUAL(-1, linkedList_indexOf(list, value));
- LONGS_EQUAL(-1, linkedList_indexOf(list, value2));
- LONGS_EQUAL(-1, linkedList_indexOf(list, value3));
- LONGS_EQUAL(-1, linkedList_indexOf(list, NULL));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value2));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value3));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, NULL));
- linkedList_addElement(list, value);
- LONGS_EQUAL(0, linkedList_indexOf(list, value));
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(0, linkedList_indexOf(list, value));
- linkedList_addElement(list, value2);
- LONGS_EQUAL(1, linkedList_indexOf(list, value2));
+ linkedList_addElement(list, value2);
+ LONGS_EQUAL(1, linkedList_indexOf(list, value2));
- linkedList_addElement(list, value3);
- LONGS_EQUAL(2, linkedList_indexOf(list, value3));
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(2, linkedList_indexOf(list, value3));
- linkedList_addElement(list, NULL);
- LONGS_EQUAL(3, linkedList_indexOf(list, NULL));
+ linkedList_addElement(list, NULL);
+ LONGS_EQUAL(3, linkedList_indexOf(list, NULL));
- free(value);
- free(value2);
- free(value3);
+ free(value);
+ free(value2);
+ free(value3);
}
//----------------------LINKED LIST ITERATOR TESTS----------------------
TEST(linked_list_iterator, create){
- linked_list_iterator_pt it_list = linkedListIterator_create(list,0);
- CHECK(it_list != NULL);
- linkedListIterator_destroy(it_list);
+ linked_list_iterator_pt it_list = linkedListIterator_create(list,0);
+ CHECK(it_list != NULL);
+ linkedListIterator_destroy(it_list);
- it_list = linkedListIterator_create(list,666);
- POINTERS_EQUAL(NULL, it_list);
+ it_list = linkedListIterator_create(list,666);
+ POINTERS_EQUAL(NULL, it_list);
}
TEST(linked_list_iterator, hasNext){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
- CHECK(linkedListIterator_hasNext(it_list));
+ it_list = linkedListIterator_create(list, 0);
+ CHECK(linkedListIterator_hasNext(it_list));
- linkedListIterator_next(it_list);
- CHECK(linkedListIterator_hasNext(it_list));
+ linkedListIterator_next(it_list);
+ CHECK(linkedListIterator_hasNext(it_list));
- linkedListIterator_next(it_list);
- CHECK(linkedListIterator_hasNext(it_list));
+ linkedListIterator_next(it_list);
+ CHECK(linkedListIterator_hasNext(it_list));
- linkedListIterator_next(it_list);
- CHECK(!linkedListIterator_hasNext(it_list));
+ linkedListIterator_next(it_list);
+ CHECK(!linkedListIterator_hasNext(it_list));
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, hasPrevious){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 3);
- CHECK(linkedListIterator_hasPrevious(it_list));
+ it_list = linkedListIterator_create(list, 3);
+ CHECK(linkedListIterator_hasPrevious(it_list));
- linkedListIterator_previous(it_list);
- CHECK(linkedListIterator_hasPrevious(it_list));
+ linkedListIterator_previous(it_list);
+ CHECK(linkedListIterator_hasPrevious(it_list));
- linkedListIterator_previous(it_list);
- CHECK(linkedListIterator_hasPrevious(it_list));
+ linkedListIterator_previous(it_list);
+ CHECK(linkedListIterator_hasPrevious(it_list));
- linkedListIterator_previous(it_list);
- CHECK(!linkedListIterator_hasPrevious(it_list));
+ linkedListIterator_previous(it_list);
+ CHECK(!linkedListIterator_hasPrevious(it_list));
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, next){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
-
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
- STRCMP_EQUAL(value, (char*) linkedListIterator_next(it_list));
- STRCMP_EQUAL(value2, (char*) linkedListIterator_next(it_list));
- STRCMP_EQUAL(value3, (char*) linkedListIterator_next(it_list));
- POINTERS_EQUAL(NULL, linkedListIterator_next(it_list));
-
- //mess up the expected and real changecount, code should check and handle
- linkedList_addElement(list, value);
- linkedListIterator_next(it_list);
-
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+ STRCMP_EQUAL(value, (char*) linkedListIterator_next(it_list));
+ STRCMP_EQUAL(value2, (char*) linkedListIterator_next(it_list));
+ STRCMP_EQUAL(value3, (char*) linkedListIterator_next(it_list));
+ POINTERS_EQUAL(NULL, linkedListIterator_next(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_next(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, previous){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
-
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 3);
- STRCMP_EQUAL(value3, (char*) linkedListIterator_previous(it_list));
- STRCMP_EQUAL(value2, (char*) linkedListIterator_previous(it_list));
- STRCMP_EQUAL(value, (char*) linkedListIterator_previous(it_list));
- POINTERS_EQUAL(NULL, linkedListIterator_previous(it_list));
-
- //mess up the expected and real changecount, code should check and handle
- linkedListIterator_destroy(it_list);
- it_list = linkedListIterator_create(list, 3);
- linkedList_addElement(list, value);
- linkedListIterator_previous(it_list);
-
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 3);
+ STRCMP_EQUAL(value3, (char*) linkedListIterator_previous(it_list));
+ STRCMP_EQUAL(value2, (char*) linkedListIterator_previous(it_list));
+ STRCMP_EQUAL(value, (char*) linkedListIterator_previous(it_list));
+ POINTERS_EQUAL(NULL, linkedListIterator_previous(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedListIterator_destroy(it_list);
+ it_list = linkedListIterator_create(list, 3);
+ linkedList_addElement(list, value);
+ linkedListIterator_previous(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, nextIndex){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
-
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
- LONGS_EQUAL(0, linkedListIterator_nextIndex(it_list));
- linkedListIterator_next(it_list);
- LONGS_EQUAL(1, linkedListIterator_nextIndex(it_list));
- linkedListIterator_next(it_list);
- LONGS_EQUAL(2, linkedListIterator_nextIndex(it_list));
-
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+ LONGS_EQUAL(0, linkedListIterator_nextIndex(it_list));
+ linkedListIterator_next(it_list);
+ LONGS_EQUAL(1, linkedListIterator_nextIndex(it_list));
+ linkedListIterator_next(it_list);
+ LONGS_EQUAL(2, linkedListIterator_nextIndex(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, previousIndex){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
-
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 3);
- LONGS_EQUAL(2, linkedListIterator_previousIndex(it_list));
- linkedListIterator_previous(it_list);
- LONGS_EQUAL(1, linkedListIterator_previousIndex(it_list));
- linkedListIterator_previous(it_list);
- LONGS_EQUAL(0, linkedListIterator_previousIndex(it_list));
-
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 3);
+ LONGS_EQUAL(2, linkedListIterator_previousIndex(it_list));
+ linkedListIterator_previous(it_list);
+ LONGS_EQUAL(1, linkedListIterator_previousIndex(it_list));
+ linkedListIterator_previous(it_list);
+ LONGS_EQUAL(0, linkedListIterator_previousIndex(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, set){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- linkedListIterator_set(it_list, NULL);
- linkedListIterator_next(it_list);
- linkedListIterator_next(it_list);
- linkedListIterator_set(it_list, value3);
- linkedListIterator_next(it_list);
- linkedListIterator_set(it_list, value2);
+ linkedListIterator_set(it_list, NULL);
+ linkedListIterator_next(it_list);
+ linkedListIterator_next(it_list);
+ linkedListIterator_set(it_list, value3);
+ linkedListIterator_next(it_list);
+ linkedListIterator_set(it_list, value2);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 2));
- //mess up the expected and real changecount, code should check and handle
- linkedList_addElement(list, value);
- linkedListIterator_set(it_list, value);
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_set(it_list, value);
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, add){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
- linkedList_addElement(list, value);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
- linkedListIterator_next(it_list);
- linkedListIterator_add(it_list, value2);
+ linkedListIterator_next(it_list);
+ linkedListIterator_add(it_list, value2);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
- //mess up the expected and real changecount, code should check and handle
- linkedList_addElement(list, value);
- linkedListIterator_add(it_list, value2);
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_add(it_list, value2);
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
TEST(linked_list_iterator, remove){
- char * value = my_strdup("element");
- char * value2 = my_strdup("element2");
- char * value3 = my_strdup("element3");
- linked_list_iterator_pt it_list;
-
- linkedList_addElement(list, value);
- linkedList_addElement(list, value2);
- linkedList_addElement(list, value3);
- it_list = linkedListIterator_create(list, 0);
-
- LONGS_EQUAL(3, list->size);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
-
- linkedListIterator_next(it_list);
- linkedListIterator_next(it_list);
- linkedListIterator_remove(it_list);
- LONGS_EQUAL(2, list->size);
- STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
- STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
-
- //mess up the expected and real changecount, code should check and handle
- linkedList_addElement(list, value);
- linkedListIterator_remove(it_list);
-
- free(value);
- free(value2);
- free(value3);
- linkedListIterator_destroy(it_list);
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+
+ LONGS_EQUAL(3, list->size);
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedListIterator_next(it_list);
+ linkedListIterator_next(it_list);
+ linkedListIterator_remove(it_list);
+ LONGS_EQUAL(2, list->size);
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_remove(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
}
diff --git a/libs/utils/private/test/properties_test.cpp b/libs/utils/private/test/properties_test.cpp
index e2f2134..95bf379 100644
--- a/libs/utils/private/test/properties_test.cpp
+++ b/libs/utils/private/test/properties_test.cpp
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* properties_test.cpp
@@ -37,205 +37,204 @@ extern "C" {
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
TEST_GROUP(properties) {
- properties_pt properties;
+ celix_properties_t *properties;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
+ void teardown() {
+ mock().checkExpectations();
+ mock().clear();
+ }
};
TEST(properties, create) {
- properties = properties_create();
- CHECK(properties);
+ properties = celix_properties_create();
+ CHECK(properties);
- properties_destroy(properties);
+ celix_properties_destroy(properties);
}
TEST(properties, load) {
- char propertiesFile[] = "resources-test/properties.txt";
- properties = properties_load(propertiesFile);
- LONGS_EQUAL(4, hashMap_size(properties));
+ char propertiesFile[] = "resources-test/properties.txt";
+ properties = celix_properties_load(propertiesFile);
+ LONGS_EQUAL(4, hashMap_size(properties));
- const char keyA[] = "a";
- const char *valueA = properties_get(properties, keyA);
- STRCMP_EQUAL("b", valueA);
+ const char keyA[] = "a";
+ const char *valueA = celix_properties_get(properties, keyA, NULL);
+ STRCMP_EQUAL("b", valueA);
- const char keyNiceA[] = "nice_a";
- const char *valueNiceA = properties_get(properties, keyNiceA);
- STRCMP_EQUAL("nice_b", valueNiceA);
+ const char keyNiceA[] = "nice_a";
+ const char *valueNiceA = celix_properties_get(properties, keyNiceA, NULL);
+ STRCMP_EQUAL("nice_b", valueNiceA);
- const char keyB[] = "b";
- const char *valueB = properties_get(properties, keyB);
- STRCMP_EQUAL("c \t d", valueB);
+ const char keyB[] = "b";
+ const char *valueB = celix_properties_get(properties, keyB, NULL);
+ STRCMP_EQUAL("c \t d", valueB);
- properties_destroy(properties);
+ celix_properties_destroy(properties);
}
TEST(properties, asLong) {
- celix_properties_t *props = celix_properties_create();
- celix_properties_set(props, "t1", "42");
- celix_properties_set(props, "t2", "-42");
- celix_properties_set(props, "t3", "");
- celix_properties_set(props, "t4", "42 bla"); //converts to 42
- celix_properties_set(props, "t5", "bla");
+ celix_properties_t *props = celix_properties_create();
+ celix_properties_set(props, "t1", "42");
+ celix_properties_set(props, "t2", "-42");
+ celix_properties_set(props, "t3", "");
+ celix_properties_set(props, "t4", "42 bla"); //converts to 42
+ celix_properties_set(props, "t5", "bla");
- long v = celix_properties_getAsLong(props, "t1", -1);
- LONGS_EQUAL(42, v);
+ long v = celix_properties_getAsLong(props, "t1", -1);
+ LONGS_EQUAL(42, v);
- v = celix_properties_getAsLong(props, "t2", -1);
- LONGS_EQUAL(-42, v);
+ v = celix_properties_getAsLong(props, "t2", -1);
+ LONGS_EQUAL(-42, v);
- v = celix_properties_getAsLong(props, "t3", -1);
- LONGS_EQUAL(-1, v);
+ v = celix_properties_getAsLong(props, "t3", -1);
+ LONGS_EQUAL(-1, v);
- v = celix_properties_getAsLong(props, "t4", -1);
- LONGS_EQUAL(42, v);
+ v = celix_properties_getAsLong(props, "t4", -1);
+ LONGS_EQUAL(42, v);
- v = celix_properties_getAsLong(props, "t5", -1);
- LONGS_EQUAL(-1, v);
+ v = celix_properties_getAsLong(props, "t5", -1);
+ LONGS_EQUAL(-1, v);
- v = celix_properties_getAsLong(props, "non-existing", -1);
- LONGS_EQUAL(-1, v);
+ v = celix_properties_getAsLong(props, "non-existing", -1);
+ LONGS_EQUAL(-1, v);
- celix_properties_destroy(props);
+ celix_properties_destroy(props);
}
TEST(properties, store) {
- char propertiesFile[] = "resources-test/properties_out.txt";
- properties = properties_create();
- char keyA[] = "x";
- char keyB[] = "y";
- char valueA[] = "1";
- char valueB[] = "2";
- properties_set(properties, keyA, valueA);
- properties_set(properties, keyB, valueB);
- properties_store(properties, propertiesFile, NULL);
-
- properties_destroy(properties);
+ char propertiesFile[] = "resources-test/properties_out.txt";
+ properties = celix_properties_create();
+ char keyA[] = "x";
+ char keyB[] = "y";
+ char valueA[] = "1";
+ char valueB[] = "2";
+ celix_properties_set(properties, keyA, valueA);
+ celix_properties_set(properties, keyB, valueB);
+ celix_properties_store(properties, propertiesFile, NULL);
+
+ celix_properties_destroy(properties);
}
TEST(properties, copy) {
- properties_pt copy;
- char propertiesFile[] = "resources-test/properties.txt";
- properties = properties_load(propertiesFile);
- LONGS_EQUAL(4, hashMap_size(properties));
+ char propertiesFile[] = "resources-test/properties.txt";
+ properties = celix_properties_load(propertiesFile);
+ LONGS_EQUAL(4, hashMap_size(properties));
- properties_copy(properties, ©);
+ celix_properties_t *copy = celix_properties_copy(properties);
- char keyA[] = "a";
- const char *valueA = properties_get(copy, keyA);
- STRCMP_EQUAL("b", valueA);
- const char keyB[] = "b";
- STRCMP_EQUAL("c \t d", properties_get(copy, keyB));
+ char keyA[] = "a";
+ const char *valueA = celix_properties_get(copy, keyA, NULL);
+ STRCMP_EQUAL("b", valueA);
+ const char keyB[] = "b";
+ STRCMP_EQUAL("c \t d", celix_properties_get(copy, keyB, NULL));
- properties_destroy(properties);
- properties_destroy(copy);
+ celix_properties_destroy(properties);
+ celix_properties_destroy(copy);
}
TEST(properties, getSet) {
- properties = properties_create();
- char keyA[] = "x";
- char keyB[] = "y";
- char keyC[] = "z";
- char valueA[] = "1";
- char valueB[] = "2";
- char valueC[] = "3";
- properties_set(properties, keyA, valueA);
- properties_set(properties, keyB, valueB);
-
- STRCMP_EQUAL(valueA, properties_get(properties, keyA));
- STRCMP_EQUAL(valueB, properties_get(properties, keyB));
- STRCMP_EQUAL(valueC, properties_getWithDefault(properties, keyC, valueC));
-
- properties_destroy(properties);
+ properties = celix_properties_create();
+ char keyA[] = "x";
+ char keyB[] = "y";
+ char keyC[] = "z";
+ char valueA[] = "1";
+ char valueB[] = "2";
+ char valueC[] = "3";
+ celix_properties_set(properties, keyA, valueA);
+ celix_properties_set(properties, keyB, valueB);
+
+ STRCMP_EQUAL(valueA, celix_properties_get(properties, keyA, NULL));
+ STRCMP_EQUAL(valueB, celix_properties_get(properties, keyB, NULL));
+ STRCMP_EQUAL(valueC, celix_properties_get(properties, keyC, valueC));
+
+ celix_properties_destroy(properties);
}
TEST(properties, longTest) {
- properties = properties_create();
-
- celix_properties_set(properties, "a", "2");
- celix_properties_set(properties, "b", "-10032L");
- celix_properties_set(properties, "c", "");
- celix_properties_set(properties, "d", "garbage");
-
- long a = celix_properties_getAsLong(properties, "a", -1L);
- long b = celix_properties_getAsLong(properties, "b", -1L);
- long c = celix_properties_getAsLong(properties, "c", -1L);
- long d = celix_properties_getAsLong(properties, "d", -1L);
- long e = celix_properties_getAsLong(properties, "e", -1L);
-
- CHECK_EQUAL(2, a);
- CHECK_EQUAL(-10032L, b);
- CHECK_EQUAL(-1L, c);
- CHECK_EQUAL(-1L, d);
- CHECK_EQUAL(-1L, e);
-
- celix_properties_setLong(properties, "a", 3L);
- celix_properties_setLong(properties, "b", -4L);
- a = celix_properties_getAsLong(properties, "a", -1L);
- b = celix_properties_getAsLong(properties, "b", -1L);
- CHECK_EQUAL(3L, a);
- CHECK_EQUAL(-4L, b);
-
- celix_properties_destroy(properties);
+ properties = celix_properties_create();
+
+ celix_properties_set(properties, "a", "2");
+ celix_properties_set(properties, "b", "-10032L");
+ celix_properties_set(properties, "c", "");
+ celix_properties_set(properties, "d", "garbage");
+
+ long a = celix_properties_getAsLong(properties, "a", -1L);
+ long b = celix_properties_getAsLong(properties, "b", -1L);
+ long c = celix_properties_getAsLong(properties, "c", -1L);
+ long d = celix_properties_getAsLong(properties, "d", -1L);
+ long e = celix_properties_getAsLong(properties, "e", -1L);
+
+ CHECK_EQUAL(2, a);
+ CHECK_EQUAL(-10032L, b);
+ CHECK_EQUAL(-1L, c);
+ CHECK_EQUAL(-1L, d);
+ CHECK_EQUAL(-1L, e);
+
+ celix_properties_setLong(properties, "a", 3L);
+ celix_properties_setLong(properties, "b", -4L);
+ a = celix_properties_getAsLong(properties, "a", -1L);
+ b = celix_properties_getAsLong(properties, "b", -1L);
+ CHECK_EQUAL(3L, a);
+ CHECK_EQUAL(-4L, b);
+
+ celix_properties_destroy(properties);
}
TEST(properties, boolTest) {
- properties = properties_create();
-
- celix_properties_set(properties, "a", "true");
- celix_properties_set(properties, "b", "false");
- celix_properties_set(properties, "c", " true ");
- celix_properties_set(properties, "d", "garbage");
-
- bool a = celix_properties_getAsBool(properties, "a", false);
- bool b = celix_properties_getAsBool(properties, "b", true);
- bool c = celix_properties_getAsBool(properties, "c", false);
- bool d = celix_properties_getAsBool(properties, "d", true);
- bool e = celix_properties_getAsBool(properties, "e", false);
- bool f = celix_properties_getAsBool(properties, "f", true);
-
- CHECK_EQUAL(true, a);
- CHECK_EQUAL(false, b);
- CHECK_EQUAL(true, c);
- CHECK_EQUAL(true, d);
- CHECK_EQUAL(false, e);
- CHECK_EQUAL(true, f);
-
- celix_properties_setBool(properties, "a", true);
- celix_properties_setBool(properties, "b", false);
- a = celix_properties_getAsBool(properties, "a", false);
- b = celix_properties_getAsBool(properties, "b", true);
- CHECK_EQUAL(true, a);
- CHECK_EQUAL(false, b);
-
- celix_properties_destroy(properties);
+ properties = celix_properties_create();
+
+ celix_properties_set(properties, "a", "true");
+ celix_properties_set(properties, "b", "false");
+ celix_properties_set(properties, "c", " true ");
+ celix_properties_set(properties, "d", "garbage");
+
+ bool a = celix_properties_getAsBool(properties, "a", false);
+ bool b = celix_properties_getAsBool(properties, "b", true);
+ bool c = celix_properties_getAsBool(properties, "c", false);
+ bool d = celix_properties_getAsBool(properties, "d", true);
+ bool e = celix_properties_getAsBool(properties, "e", false);
+ bool f = celix_properties_getAsBool(properties, "f", true);
+
+ CHECK_EQUAL(true, a);
+ CHECK_EQUAL(false, b);
+ CHECK_EQUAL(true, c);
+ CHECK_EQUAL(true, d);
+ CHECK_EQUAL(false, e);
+ CHECK_EQUAL(true, f);
+
+ celix_properties_setBool(properties, "a", true);
+ celix_properties_setBool(properties, "b", false);
+ a = celix_properties_getAsBool(properties, "a", false);
+ b = celix_properties_getAsBool(properties, "b", true);
+ CHECK_EQUAL(true, a);
+ CHECK_EQUAL(false, b);
+
+ celix_properties_destroy(properties);
}
TEST(properties, sizeAndIteratorTest) {
- celix_properties_t *props = celix_properties_create();
- CHECK_EQUAL(0, celix_properties_size(props));
- celix_properties_set(props, "a", "1");
- celix_properties_set(props, "b", "2");
- CHECK_EQUAL(2, celix_properties_size(props));
- celix_properties_set(props, "c", " 3 ");
- celix_properties_set(props, "d", "4");
- CHECK_EQUAL(4, celix_properties_size(props));
-
- int count = 0;
- const char *_key = NULL;
- CELIX_PROPERTIES_FOR_EACH(props, _key) {
- count++;
- }
- CHECK_EQUAL(4, count);
-
- celix_properties_destroy(props);
+ celix_properties_t *props = celix_properties_create();
+ CHECK_EQUAL(0, celix_properties_size(props));
+ celix_properties_set(props, "a", "1");
+ celix_properties_set(props, "b", "2");
+ CHECK_EQUAL(2, celix_properties_size(props));
+ celix_properties_set(props, "c", " 3 ");
+ celix_properties_set(props, "d", "4");
+ CHECK_EQUAL(4, celix_properties_size(props));
+
+ int count = 0;
+ const char *_key = NULL;
+ CELIX_PROPERTIES_FOR_EACH(props, _key) {
+ count++;
+ }
+ CHECK_EQUAL(4, count);
+
+ celix_properties_destroy(props);
}
\ No newline at end of file
diff --git a/libs/utils/private/test/thread_pool_test.cpp b/libs/utils/private/test/thread_pool_test.cpp
index 5dae4c8..004bfa1 100644
--- a/libs/utils/private/test/thread_pool_test.cpp
+++ b/libs/utils/private/test/thread_pool_test.cpp
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list_test.cpp
*
- * \date Sep 15, 2015
- * \author Menno van der Graaf & Alexander
- * \copyright Apache License, Version 2.0
+ * \date Sep 15, 2015
+ * \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 <unistd.h>
@@ -42,14 +43,14 @@ int sum=0;
void * increment(void *) {
- celixThreadMutex_lock(&mutex);
- sum ++;
- celixThreadMutex_unlock(&mutex);
- return NULL;
+ celixThreadMutex_lock(&mutex);
+ sum ++;
+ celixThreadMutex_unlock(&mutex);
+ return NULL;
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
@@ -58,13 +59,13 @@ int main(int argc, char** argv) {
//----------------------TESTGROUP DEFINES----------------------
TEST_GROUP(thread_pool) {
- threadpool myPool;
+ threadpool myPool;
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown(void) {
- }
+ void teardown(void) {
+ }
};
@@ -72,47 +73,47 @@ TEST_GROUP(thread_pool) {
TEST(thread_pool, create) {
- myPool = thpool_init(5); // pool of 5 threads
- CHECK((myPool != NULL));
- thpool_destroy(myPool);
+ myPool = thpool_init(5); // pool of 5 threads
+ CHECK((myPool != NULL));
+ thpool_destroy(myPool);
}
TEST(thread_pool, do_work) {
- myPool = thpool_init(5); // pool of 5 threads
- celixThreadMutex_create(&mutex, NULL);
- CHECK((myPool != NULL));
- int n;
- sum = 0;
- int num_jobs = 1000;
- for (n = 0; n < num_jobs; n++){
- thpool_add_work(myPool, increment, NULL);
- }
- thpool_wait(myPool);
- thpool_destroy(myPool);
- CHECK_EQUAL(1000, sum);
- celixThreadMutex_destroy(&mutex);
+ myPool = thpool_init(5); // pool of 5 threads
+ celixThreadMutex_create(&mutex, NULL);
+ CHECK((myPool != NULL));
+ int n;
+ sum = 0;
+ int num_jobs = 1000;
+ for (n = 0; n < num_jobs; n++){
+ thpool_add_work(myPool, increment, NULL);
+ }
+ thpool_wait(myPool);
+ thpool_destroy(myPool);
+ CHECK_EQUAL(1000, sum);
+ celixThreadMutex_destroy(&mutex);
}
TEST(thread_pool, do_work_with_pause) {
- myPool = thpool_init(5); // pool of 5 threads
- celixThreadMutex_create(&mutex, NULL);
- CHECK((myPool != NULL));
- int n;
- sum = 0;
- int num_jobs = 500000;
- for (n = 0; n < num_jobs; n++){
- thpool_add_work(myPool, increment, NULL);
- }
- sleep(1);
- thpool_pause(myPool);
- for (n = 0; n < num_jobs; n++){
- thpool_add_work(myPool, increment, NULL);
- }
- thpool_resume(myPool);
- thpool_wait(myPool);
- thpool_destroy(myPool);
- CHECK_EQUAL(1000000, sum);
- celixThreadMutex_destroy(&mutex);
+ myPool = thpool_init(5); // pool of 5 threads
+ celixThreadMutex_create(&mutex, NULL);
+ CHECK((myPool != NULL));
+ int n;
+ sum = 0;
+ int num_jobs = 500000;
+ for (n = 0; n < num_jobs; n++){
+ thpool_add_work(myPool, increment, NULL);
+ }
+ sleep(1);
+ thpool_pause(myPool);
+ for (n = 0; n < num_jobs; n++){
+ thpool_add_work(myPool, increment, NULL);
+ }
+ thpool_resume(myPool);
+ thpool_wait(myPool);
+ thpool_destroy(myPool);
+ CHECK_EQUAL(1000000, sum);
+ celixThreadMutex_destroy(&mutex);
}
diff --git a/libs/utils/private/test/utils_test.cpp b/libs/utils/private/test/utils_test.cpp
index 8f939c0..4801191 100644
--- a/libs/utils/private/test/utils_test.cpp
+++ b/libs/utils/private/test/utils_test.cpp
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* utils_test.cpp
@@ -23,6 +23,7 @@
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
+
#include "string.h"
#include <stdlib.h>
#include <string.h>
@@ -37,262 +38,262 @@ extern "C"
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
TEST_GROUP(utils) {
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown() {
- }
+ void teardown() {
+ }
};
static char* my_strdup(const char* s){
- if(s==NULL){
- return NULL;
- }
+ if(s==NULL){
+ return NULL;
+ }
- size_t len = strlen(s);
+ size_t len = strlen(s);
- char *d = (char*) calloc (len + 1,sizeof(char));
+ char *d = (char*) calloc (len + 1,sizeof(char));
- if (d == NULL){
- return NULL;
- }
+ if (d == NULL){
+ return NULL;
+ }
- strncpy (d,s,len);
- return d;
+ strncpy (d,s,len);
+ return d;
}
TEST(utils, stringHash) {
- char * toHash = my_strdup("abc");
- unsigned int hash;
- hash = utils_stringHash((void *) toHash);
- LONGS_EQUAL(193485963, hash);
-
- free(toHash);
- toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
- hash = utils_stringHash((void *) toHash);
- LONGS_EQUAL(1532304168, hash);
-
- free(toHash);
- toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
- hash = utils_stringHash((void *) toHash);
- LONGS_EQUAL(3721605959, hash);
- free(toHash);
+ char * toHash = my_strdup("abc");
+ unsigned int hash;
+ hash = utils_stringHash((void *) toHash);
+ LONGS_EQUAL(193485963, hash);
+
+ free(toHash);
+ toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
+ hash = utils_stringHash((void *) toHash);
+ LONGS_EQUAL(1532304168, hash);
+
+ free(toHash);
+ toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
+ hash = utils_stringHash((void *) toHash);
+ LONGS_EQUAL(3721605959, hash);
+ free(toHash);
}
TEST(utils, stringEquals) {
- // Compare with equal strings
- char * org = my_strdup("abc");
- char * cmp = my_strdup("abc");
-
- int result = utils_stringEquals((void *) org, (void *) cmp);
- CHECK(result);
-
- // Compare with no equal strings
- free(cmp);
- cmp = my_strdup("abcd");
-
- result = utils_stringEquals((void *) org, (void *) cmp);
- CHECK_FALSE(result);
-
- // Compare with numeric strings
- free(org);
- free(cmp);
- org = my_strdup("123");
- cmp = my_strdup("123");
-
- result = utils_stringEquals((void *) org, (void *) cmp);
- CHECK(result);
-
- // Compare with long strings
- free(org);
- free(cmp);
- org = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
- cmp = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
- "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
-
- result = utils_stringEquals((void *) org, (void *) cmp);
- CHECK(result);
-
- free(org);
- free(cmp);
+ // Compare with equal strings
+ char * org = my_strdup("abc");
+ char * cmp = my_strdup("abc");
+
+ int result = utils_stringEquals((void *) org, (void *) cmp);
+ CHECK(result);
+
+ // Compare with no equal strings
+ free(cmp);
+ cmp = my_strdup("abcd");
+
+ result = utils_stringEquals((void *) org, (void *) cmp);
+ CHECK_FALSE(result);
+
+ // Compare with numeric strings
+ free(org);
+ free(cmp);
+ org = my_strdup("123");
+ cmp = my_strdup("123");
+
+ result = utils_stringEquals((void *) org, (void *) cmp);
+ CHECK(result);
+
+ // Compare with long strings
+ free(org);
+ free(cmp);
+ org = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
+ cmp = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+ "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz");
+
+ result = utils_stringEquals((void *) org, (void *) cmp);
+ CHECK(result);
+
+ free(org);
+ free(cmp);
}
TEST(utils, string_ndup){
- // Compare with equal strings
- const char * org = "abc";
- char * cmp = NULL;
-
- cmp = string_ndup(org, 3);
- STRCMP_EQUAL(org, cmp);
- free(cmp);
-
- org = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
- cmp = string_ndup(org, 50);
- STRCMP_EQUAL(org, cmp);
- free(cmp);
-
- cmp = string_ndup(org, 25);
- LONGS_EQUAL(25, strlen(cmp));
- free(cmp);
+ // Compare with equal strings
+ const char * org = "abc";
+ char * cmp = NULL;
+
+ cmp = string_ndup(org, 3);
+ STRCMP_EQUAL(org, cmp);
+ free(cmp);
+
+ org = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
+ cmp = string_ndup(org, 50);
+ STRCMP_EQUAL(org, cmp);
+ free(cmp);
+
+ cmp = string_ndup(org, 25);
+ LONGS_EQUAL(25, strlen(cmp));
+ free(cmp);
}
TEST(utils, stringTrim) {
- // Multiple whitespaces, before, after and in between
- char * toTrim = my_strdup(" a b c ");
- char * result = utils_stringTrim(toTrim);
+ // Multiple whitespaces, before, after and in between
+ char * toTrim = my_strdup(" a b c ");
+ char * result = utils_stringTrim(toTrim);
- STRCMP_EQUAL("a b c", result);
+ STRCMP_EQUAL("a b c", result);
- // No whitespaces
- free(toTrim);
- toTrim = my_strdup("abc");
- result = utils_stringTrim(toTrim);
+ // No whitespaces
+ free(toTrim);
+ toTrim = my_strdup("abc");
+ result = utils_stringTrim(toTrim);
- STRCMP_EQUAL("abc", result);
+ STRCMP_EQUAL("abc", result);
- // Only whitespace before
- free(toTrim);
- toTrim = my_strdup(" abc");
- result = utils_stringTrim(toTrim);
+ // Only whitespace before
+ free(toTrim);
+ toTrim = my_strdup(" abc");
+ result = utils_stringTrim(toTrim);
- STRCMP_EQUAL("abc", result);
+ STRCMP_EQUAL("abc", result);
- // Only whitespace after
- free(toTrim);
- toTrim = my_strdup("abc ");
- result = utils_stringTrim(toTrim);
+ // Only whitespace after
+ free(toTrim);
+ toTrim = my_strdup("abc ");
+ result = utils_stringTrim(toTrim);
- STRCMP_EQUAL("abc", result);
+ STRCMP_EQUAL("abc", result);
- // Whitespace other then space (tab, cr..).
- free(toTrim);
- toTrim = my_strdup("\tabc \n asdf \n");
- result = utils_stringTrim(toTrim);
+ // Whitespace other than space (tab, cr..).
+ free(toTrim);
+ toTrim = my_strdup("\tabc \n asdf \n");
+ result = utils_stringTrim(toTrim);
- STRCMP_EQUAL("abc \n asdf", result);
+ STRCMP_EQUAL("abc \n asdf", result);
- free(toTrim);
+ free(toTrim);
}
TEST(utils, thread_equalsSelf){
- celix_thread thread = celixThread_self();
- bool get;
+ celix_thread thread = celixThread_self();
+ bool get;
- LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get));
- CHECK(get);
+ LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get));
+ CHECK(get);
- thread.thread = (pthread_t) 0x42;
- LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get));
- CHECK_FALSE(get);
+ thread.thread = (pthread_t) 0x42;
+ LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get));
+ CHECK_FALSE(get);
}
TEST(utils, isNumeric) {
- // Check numeric string
- char * toCheck = my_strdup("42");
-
- bool result;
- celix_status_t status = utils_isNumeric(toCheck, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(result);
-
- // Check non numeric string
- free(toCheck);
- toCheck = my_strdup("42b");
- status = utils_isNumeric(toCheck, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(!result);
-
- free(toCheck);
+ // Check numeric string
+ char * toCheck = my_strdup("42");
+
+ bool result;
+ celix_status_t status = utils_isNumeric(toCheck, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(result);
+
+ // Check non numeric string
+ free(toCheck);
+ toCheck = my_strdup("42b");
+ status = utils_isNumeric(toCheck, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(!result);
+
+ free(toCheck);
}
TEST(utils, compareServiceIdsAndRanking){
- int ret;
- //service 1 is higher ranked and has a irrelevant ID
- ret = utils_compareServiceIdsAndRanking(2,2,1,1);
- LONGS_EQUAL(1, ret);
-
- //service 1 is equally ranked and has a lower ID
- ret = utils_compareServiceIdsAndRanking(1,1,2,1);
- LONGS_EQUAL(1, ret);
-
- //service 1 is equally ranked and has a higher ID
- ret = utils_compareServiceIdsAndRanking(2,1,1,1);
- LONGS_EQUAL(-1, ret);
-
- //service 1 is lower ranked and has a irrelevant ID
- ret = utils_compareServiceIdsAndRanking(1,1,2,2);
- LONGS_EQUAL(-1, ret);
-
- //service 1 is equal in ID and irrelevantly ranked
- ret = utils_compareServiceIdsAndRanking(1,1,1,1);
- LONGS_EQUAL(0, ret);
+ int ret;
+ //service 1 is higher ranked and has a irrelevant ID
+ ret = utils_compareServiceIdsAndRanking(2,2,1,1);
+ LONGS_EQUAL(1, ret);
+
+ //service 1 is equally ranked and has a lower ID
+ ret = utils_compareServiceIdsAndRanking(1,1,2,1);
+ LONGS_EQUAL(1, ret);
+
+ //service 1 is equally ranked and has a higher ID
+ ret = utils_compareServiceIdsAndRanking(2,1,1,1);
+ LONGS_EQUAL(-1, ret);
+
+ //service 1 is lower ranked and has a irrelevant ID
+ ret = utils_compareServiceIdsAndRanking(1,1,2,2);
+ LONGS_EQUAL(-1, ret);
+
+ //service 1 is equal in ID and irrelevantly ranked
+ ret = utils_compareServiceIdsAndRanking(1,1,1,1);
+ LONGS_EQUAL(0, ret);
}
diff --git a/libs/utils/private/test/version_range_test.cpp b/libs/utils/private/test/version_range_test.cpp
index 1e1336c..9ac1d24 100644
--- a/libs/utils/private/test/version_range_test.cpp
+++ b/libs/utils/private/test/version_range_test.cpp
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* version_range_test.cpp
@@ -41,212 +41,212 @@ framework_logger_pt logger = (framework_logger_pt) 0x42;
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s) {
- if (s == NULL) {
- return NULL;
- }
+ if (s == NULL) {
+ return NULL;
+ }
- size_t len = strlen(s);
+ size_t len = strlen(s);
- char *d = (char*) calloc(len + 1, sizeof(char));
+ char *d = (char*) calloc(len + 1, sizeof(char));
- if (d == NULL) {
- return NULL;
- }
+ if (d == NULL) {
+ return NULL;
+ }
- strncpy(d, s, len);
- return d;
+ strncpy(d, s, len);
+ return d;
}
//----------------------TESTGROUP DEFINES----------------------
TEST_GROUP(version_range) {
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
+ void teardown() {
+ mock().checkExpectations();
+ mock().clear();
+ }
};
TEST(version_range, create) {
- celix_status_t status = CELIX_SUCCESS;
- version_range_pt range = NULL;
- version_pt version = (version_pt) malloc(sizeof(*version));
-
- status = versionRange_createVersionRange(version, false, version, true, &range);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C((range != NULL));
- LONGS_EQUAL(true, range->isHighInclusive);
- LONGS_EQUAL(false, range->isLowInclusive);
- POINTERS_EQUAL(version, range->low);
- POINTERS_EQUAL(version, range->high);
-
- mock().expectNCalls(2, "version_destroy")
- .withParameter("version", version);
-
- versionRange_destroy(range);
- free(version);
+ celix_status_t status = CELIX_SUCCESS;
+ version_range_pt range = NULL;
+ version_pt version = (version_pt) malloc(sizeof(*version));
+
+ status = versionRange_createVersionRange(version, false, version, true, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C((range != NULL));
+ LONGS_EQUAL(true, range->isHighInclusive);
+ LONGS_EQUAL(false, range->isLowInclusive);
+ POINTERS_EQUAL(version, range->low);
+ POINTERS_EQUAL(version, range->high);
+
+ mock().expectNCalls(2, "version_destroy")
+ .withParameter("version", version);
+
+ versionRange_destroy(range);
+ free(version);
}
TEST(version_range, createInfinite) {
- celix_status_t status = CELIX_SUCCESS;
- version_range_pt range = NULL;
- version_pt version = (version_pt) malloc(sizeof(*version));
- version->major = 1;
- version->minor = 2;
- version->micro = 3;
-
- mock()
- .expectOneCall("version_createEmptyVersion")
- .withOutputParameterReturning("version", &version, sizeof("version"));
- status = versionRange_createInfiniteVersionRange(&range);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(range != NULL);
- LONGS_EQUAL(true, range->isHighInclusive);
- LONGS_EQUAL(true, range->isLowInclusive);
- POINTERS_EQUAL(version, range->low);
- POINTERS_EQUAL(NULL, range->high);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", version);
-
- versionRange_destroy(range);
- free(version);
+ celix_status_t status = CELIX_SUCCESS;
+ version_range_pt range = NULL;
+ version_pt version = (version_pt) malloc(sizeof(*version));
+ version->major = 1;
+ version->minor = 2;
+ version->micro = 3;
+
+ mock()
+ .expectOneCall("version_createEmptyVersion")
+ .withOutputParameterReturning("version", &version, sizeof("version"));
+ status = versionRange_createInfiniteVersionRange(&range);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(range != NULL);
+ LONGS_EQUAL(true, range->isHighInclusive);
+ LONGS_EQUAL(true, range->isLowInclusive);
+ POINTERS_EQUAL(version, range->low);
+ POINTERS_EQUAL(NULL, range->high);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", version);
+
+ versionRange_destroy(range);
+ free(version);
}
TEST(version_range, isInRange) {
- bool result;
- version_range_pt range = NULL;
- version_pt version = (version_pt) malloc(sizeof(*version));
- version->major = 1;
- version->minor = 2;
- version->micro = 3;
-
- version_pt low = (version_pt) malloc(sizeof(*low));
- low->major = 1;
- low->minor = 2;
- low->micro = 3;
-
- version_pt high = (version_pt) malloc(sizeof(*high));
- high->major = 1;
- high->minor = 2;
- high->micro = 3;
-
- int stat = 1;
- mock()
- .expectNCalls(5, "version_compareTo")
- .withParameter("version", version)
- .withParameter("compare", low)
- .withOutputParameterReturning("result", &stat, sizeof(int));
- int stat2 = -1;
- mock()
- .expectNCalls(4, "version_compareTo")
- .withParameter("version", version)
- .withParameter("compare", high)
- .withOutputParameterReturning("result", &stat2, sizeof(int));
-
- versionRange_createVersionRange(low, true, high, true, &range);
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
- LONGS_EQUAL(true, result);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", low);
- mock().expectOneCall("version_destroy")
- .withParameter("version", high);
- versionRange_destroy(range);
-
- versionRange_createVersionRange(low, true, NULL, true, &range);
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
- LONGS_EQUAL(true, result);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", low);
- versionRange_destroy(range);
-
- versionRange_createVersionRange(low, false, high, true, &range);
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
- LONGS_EQUAL(true, result);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", low);
- mock().expectOneCall("version_destroy")
- .withParameter("version", high);
- versionRange_destroy(range);
-
- versionRange_createVersionRange(low, true, high, false, &range);
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
- LONGS_EQUAL(true, result);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", low);
- mock().expectOneCall("version_destroy")
- .withParameter("version", high);
- versionRange_destroy(range);
-
- versionRange_createVersionRange(low, false, high, false, &range);
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
- LONGS_EQUAL(true, result);
-
- mock().expectOneCall("version_destroy")
- .withParameter("version", low);
- mock().expectOneCall("version_destroy")
- .withParameter("version", high);
- versionRange_destroy(range);
-
- free(version);
- free(high);
- free(low);
+ bool result;
+ version_range_pt range = NULL;
+ version_pt version = (version_pt) malloc(sizeof(*version));
+ version->major = 1;
+ version->minor = 2;
+ version->micro = 3;
+
+ version_pt low = (version_pt) malloc(sizeof(*low));
+ low->major = 1;
+ low->minor = 2;
+ low->micro = 3;
+
+ version_pt high = (version_pt) malloc(sizeof(*high));
+ high->major = 1;
+ high->minor = 2;
+ high->micro = 3;
+
+ int stat = 1;
+ mock()
+ .expectNCalls(5, "version_compareTo")
+ .withParameter("version", version)
+ .withParameter("compare", low)
+ .withOutputParameterReturning("result", &stat, sizeof(int));
+ int stat2 = -1;
+ mock()
+ .expectNCalls(4, "version_compareTo")
+ .withParameter("version", version)
+ .withParameter("compare", high)
+ .withOutputParameterReturning("result", &stat2, sizeof(int));
+
+ versionRange_createVersionRange(low, true, high, true, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
+ LONGS_EQUAL(true, result);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", low);
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", high);
+ versionRange_destroy(range);
+
+ versionRange_createVersionRange(low, true, NULL, true, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
+ LONGS_EQUAL(true, result);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", low);
+ versionRange_destroy(range);
+
+ versionRange_createVersionRange(low, false, high, true, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
+ LONGS_EQUAL(true, result);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", low);
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", high);
+ versionRange_destroy(range);
+
+ versionRange_createVersionRange(low, true, high, false, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
+ LONGS_EQUAL(true, result);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", low);
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", high);
+ versionRange_destroy(range);
+
+ versionRange_createVersionRange(low, false, high, false, &range);
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result));
+ LONGS_EQUAL(true, result);
+
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", low);
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", high);
+ versionRange_destroy(range);
+
+ free(version);
+ free(high);
+ free(low);
}
TEST(version_range, parse) {
- version_range_pt range = NULL;
- version_pt low = (version_pt) malloc(sizeof(*low));
- version_pt high = (version_pt) malloc(sizeof(*high));
- char * version = my_strdup("[1.2.3,7.8.9]");
- low->major = 1;
- low->minor = 2;
- low->micro = 3;
+ version_range_pt range = NULL;
+ version_pt low = (version_pt) malloc(sizeof(*low));
+ version_pt high = (version_pt) malloc(sizeof(*high));
+ char * version = my_strdup("[1.2.3,7.8.9]");
+ low->major = 1;
+ low->minor = 2;
+ low->micro = 3;
- high->major = 7;
- high->minor = 8;
- high->micro = 9;
+ high->major = 7;
+ high->minor = 8;
+ high->micro = 9;
- mock().expectOneCall("version_destroy")
- .withParameter("version", high);
+ mock().expectOneCall("version_destroy")
+ .withParameter("version", high);
- mock().expectNCalls(2, "version_destroy")
- .withParameter("version", low);
+ mock().expectNCalls(2, "version_destroy")
+ .withParameter("version", low);
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", "1.2.3")
- .withOutputParameterReturning("version", &low, sizeof(low));
+ mock().expectOneCall("version_createVersionFromString")
+ .withParameter("versionStr", "1.2.3")
+ .withOutputParameterReturning("version", &low, sizeof(low));
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", "7.8.9")
- .withOutputParameterReturning("version", &high, sizeof(high));
+ mock().expectOneCall("version_createVersionFromString")
+ .withParameter("versionStr", "7.8.9")
+ .withOutputParameterReturning("version", &high, sizeof(high));
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range));
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range));
- versionRange_destroy(range);
- free(version);
- version = my_strdup("[1.2.3");
+ versionRange_destroy(range);
+ free(version);
+ version = my_strdup("[1.2.3");
- mock().expectOneCall("version_createVersionFromString")
- .withParameter("versionStr", "[1.2.3")
- .withOutputParameterReturning("version", &low, sizeof(low));
+ mock().expectOneCall("version_createVersionFromString")
+ .withParameter("versionStr", "[1.2.3")
+ .withOutputParameterReturning("version", &low, sizeof(low));
- LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range));
+ LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range));
- versionRange_destroy(range);
- free(version);
- free(high);
- free(low);
+ versionRange_destroy(range);
+ free(version);
+ free(high);
+ free(low);
}
diff --git a/libs/utils/private/test/version_test.cpp b/libs/utils/private/test/version_test.cpp
index 5603a33..e65a6b1 100644
--- a/libs/utils/private/test/version_test.cpp
+++ b/libs/utils/private/test/version_test.cpp
@@ -39,317 +39,317 @@ framework_logger_pt logger = (framework_logger_pt) 0x666;
}
int main(int argc, char** argv) {
- return RUN_ALL_TESTS(argc, argv);
+ return RUN_ALL_TESTS(argc, argv);
}
static char* my_strdup(const char* s){
- if(s==NULL){
- return NULL;
- }
+ if (s == NULL) {
+ return NULL;
+ }
- size_t len = strlen(s);
+ size_t len = strlen(s);
- char *d = (char*) calloc (len + 1,sizeof(char));
+ char *d = (char *) calloc(len + 1, sizeof(char));
- if (d == NULL){
- return NULL;
- }
+ if (d == NULL) {
+ return NULL;
+ }
- strncpy (d,s,len);
- return d;
+ strncpy(d,s,len);
+ return d;
}
TEST_GROUP(version) {
- void setup(void) {
- }
+ void setup(void) {
+ }
- void teardown() {
- mock().checkExpectations();
- mock().clear();
- }
+ void teardown() {
+ mock().checkExpectations();
+ mock().clear();
+ }
};
TEST(version, create) {
- version_pt version = NULL;
- char * str;
+ version_pt version = NULL;
+ char * str;
-// str = my_strdup("abc");
-// status = version_createVersion(1, 2, 3, str, &version);
-// LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+// str = my_strdup("abc");
+// status = version_createVersion(1, 2, 3, str, &version);
+// LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
- str = my_strdup("abc");
- LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version));
- CHECK_C(version != NULL);
+ str = my_strdup("abc");
+ LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version));
+ CHECK_C(version != NULL);
LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
- STRCMP_EQUAL("abc", version->qualifier);
-
- version_destroy(version);
- version = NULL;
- LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, NULL, &version));
- CHECK_C(version != NULL);
- LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
- STRCMP_EQUAL("", version->qualifier);
-
- version_destroy(version);
- version = NULL;
- free(str);
- str = my_strdup("abc");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(-1, -2, -3, str, &version));
-
- version_destroy(version);
- version = NULL;
- free(str);
- str = my_strdup("abc|xyz");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(1, 2, 3, str, &version));
-
- version_destroy(version);
- free(str);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+ STRCMP_EQUAL("abc", version->qualifier);
+
+ version_destroy(version);
+ version = NULL;
+ LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, NULL, &version));
+ CHECK_C(version != NULL);
+ LONGS_EQUAL(1, version->major);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+ STRCMP_EQUAL("", version->qualifier);
+
+ version_destroy(version);
+ version = NULL;
+ free(str);
+ str = my_strdup("abc");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(-1, -2, -3, str, &version));
+
+ version_destroy(version);
+ version = NULL;
+ free(str);
+ str = my_strdup("abc|xyz");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(1, 2, 3, str, &version));
+
+ version_destroy(version);
+ free(str);
}
TEST(version, clone) {
- version_pt version = NULL, clone = NULL;
- char * str;
+ version_pt version = NULL, clone = NULL;
+ char * str;
- str = my_strdup("abc");
- LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version));
- LONGS_EQUAL(CELIX_SUCCESS, version_clone(version, &clone));
- CHECK_C(version != NULL);
+ str = my_strdup("abc");
+ LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version));
+ LONGS_EQUAL(CELIX_SUCCESS, version_clone(version, &clone));
+ CHECK_C(version != NULL);
LONGS_EQUAL(1, clone->major);
- LONGS_EQUAL(2, clone->minor);
- LONGS_EQUAL(3, clone->micro);
- STRCMP_EQUAL("abc", clone->qualifier);
+ LONGS_EQUAL(2, clone->minor);
+ LONGS_EQUAL(3, clone->micro);
+ STRCMP_EQUAL("abc", clone->qualifier);
- version_destroy(clone);
- version_destroy(version);
- free(str);
+ version_destroy(clone);
+ version_destroy(version);
+ free(str);
}
TEST(version, createFromString) {
- version_pt version = NULL;
- celix_status_t status = CELIX_SUCCESS;
- char * str;
-
- str = my_strdup("1");
- LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version));
- CHECK_C(version != NULL);
- LONGS_EQUAL(1, version->major);
-
- version_destroy(version);
-
- free(str);
- str = my_strdup("a");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
-
- free(str);
- str = my_strdup("1.a");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
-
- free(str);
- str = my_strdup("1.1.a");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
-
- free(str);
- str = my_strdup("-1");
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
-
- free(str);
- str = my_strdup("1.2");
- version = NULL;
- LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version));
- CHECK_C(version != NULL);
- LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
-
- version_destroy(version);
-
- free(str);
- str = my_strdup("1.2.3");
- version = NULL;
- status = version_createVersionFromString(str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
- LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
-
- version_destroy(version);
- free(str);
- str = my_strdup("1.2.3.abc");
- version = NULL;
- status = version_createVersionFromString(str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
- LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
- STRCMP_EQUAL("abc", version->qualifier);
-
- version_destroy(version);
- free(str);
- str = my_strdup("1.2.3.abc_xyz");
- version = NULL;
- status = version_createVersionFromString(str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
+ version_pt version = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ char * str;
+
+ str = my_strdup("1");
+ LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version));
+ CHECK_C(version != NULL);
LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
- STRCMP_EQUAL("abc_xyz", version->qualifier);
-
- version_destroy(version);
- free(str);
- str = my_strdup("1.2.3.abc-xyz");
- version = NULL;
- status = version_createVersionFromString(str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
+
+ version_destroy(version);
+
+ free(str);
+ str = my_strdup("a");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
+
+ free(str);
+ str = my_strdup("1.a");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
+
+ free(str);
+ str = my_strdup("1.1.a");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
+
+ free(str);
+ str = my_strdup("-1");
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version));
+
+ free(str);
+ str = my_strdup("1.2");
+ version = NULL;
+ LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version));
+ CHECK_C(version != NULL);
LONGS_EQUAL(1, version->major);
- LONGS_EQUAL(2, version->minor);
- LONGS_EQUAL(3, version->micro);
- STRCMP_EQUAL("abc-xyz", version->qualifier);
+ LONGS_EQUAL(2, version->minor);
+
+ version_destroy(version);
- version_destroy(version);
- free(str);
- str = my_strdup("1.2.3.abc|xyz");
- status = version_createVersionFromString(str, &version);
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+ free(str);
+ str = my_strdup("1.2.3");
+ version = NULL;
+ status = version_createVersionFromString(str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ LONGS_EQUAL(1, version->major);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+
+ version_destroy(version);
+ free(str);
+ str = my_strdup("1.2.3.abc");
+ version = NULL;
+ status = version_createVersionFromString(str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ LONGS_EQUAL(1, version->major);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+ STRCMP_EQUAL("abc", version->qualifier);
+
+ version_destroy(version);
+ free(str);
+ str = my_strdup("1.2.3.abc_xyz");
+ version = NULL;
+ status = version_createVersionFromString(str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ LONGS_EQUAL(1, version->major);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+ STRCMP_EQUAL("abc_xyz", version->qualifier);
+
+ version_destroy(version);
+ free(str);
+ str = my_strdup("1.2.3.abc-xyz");
+ version = NULL;
+ status = version_createVersionFromString(str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ LONGS_EQUAL(1, version->major);
+ LONGS_EQUAL(2, version->minor);
+ LONGS_EQUAL(3, version->micro);
+ STRCMP_EQUAL("abc-xyz", version->qualifier);
+
+ version_destroy(version);
+ free(str);
+ str = my_strdup("1.2.3.abc|xyz");
+ status = version_createVersionFromString(str, &version);
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
- free(str);
+ free(str);
}
TEST(version, createEmptyVersion) {
- version_pt version = NULL;
- celix_status_t status = CELIX_SUCCESS;
+ version_pt version = NULL;
+ celix_status_t status = CELIX_SUCCESS;
- status = version_createEmptyVersion(&version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
+ status = version_createEmptyVersion(&version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
LONGS_EQUAL(0, version->major);
- LONGS_EQUAL(0, version->minor);
- LONGS_EQUAL(0, version->micro);
- STRCMP_EQUAL("", version->qualifier);
+ LONGS_EQUAL(0, version->minor);
+ LONGS_EQUAL(0, version->micro);
+ STRCMP_EQUAL("", version->qualifier);
- version_destroy(version);
+ version_destroy(version);
}
TEST(version, getters) {
- version_pt version = NULL;
- celix_status_t status = CELIX_SUCCESS;
- char * str;
- int major, minor, micro;
- char *qualifier;
-
- str = my_strdup("abc");
- status = version_createVersion(1, 2, 3, str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
-
- version_getMajor(version, &major);
+ version_pt version = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ char * str;
+ int major, minor, micro;
+ char *qualifier;
+
+ str = my_strdup("abc");
+ status = version_createVersion(1, 2, 3, str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+
+ version_getMajor(version, &major);
LONGS_EQUAL(1, major);
version_getMinor(version, &minor);
- LONGS_EQUAL(2, minor);
+ LONGS_EQUAL(2, minor);
- version_getMicro(version, µ);
- LONGS_EQUAL(3, micro);
+ version_getMicro(version, µ);
+ LONGS_EQUAL(3, micro);
- version_getQualifier(version, &qualifier);
- STRCMP_EQUAL("abc", qualifier);
+ version_getQualifier(version, &qualifier);
+ STRCMP_EQUAL("abc", qualifier);
- version_destroy(version);
- free(str);
+ version_destroy(version);
+ free(str);
}
TEST(version, compare) {
- version_pt version = NULL, compare = NULL;
- celix_status_t status = CELIX_SUCCESS;
- char * str;
- int result;
-
- // Base version to compare
- str = my_strdup("abc");
- status = version_createVersion(1, 2, 3, str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
-
- // Compare equality
- free(str);
- str = my_strdup("abc");
- compare = NULL;
- status = version_createVersion(1, 2, 3, str, &compare);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
- status = version_compareTo(version, compare, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- LONGS_EQUAL(0, result);
-
- // Compare against a higher version
- free(str);
- str = my_strdup("bcd");
- version_destroy(compare);
- compare = NULL;
- status = version_createVersion(1, 2, 3, str, &compare);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
- status = version_compareTo(version, compare, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK(result < 0);
-
- // Compare againts a lower version
- free(str);
- str = my_strdup("abc");
- version_destroy(compare);
- compare = NULL;
- status = version_createVersion(1, 1, 3, str, &compare);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
- status = version_compareTo(version, compare, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK(result > 0);
-
- version_destroy(compare);
- version_destroy(version);
- free(str);
+ version_pt version = NULL, compare = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ char * str;
+ int result;
+
+ // Base version to compare
+ str = my_strdup("abc");
+ status = version_createVersion(1, 2, 3, str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+
+ // Compare equality
+ free(str);
+ str = my_strdup("abc");
+ compare = NULL;
+ status = version_createVersion(1, 2, 3, str, &compare);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ status = version_compareTo(version, compare, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ LONGS_EQUAL(0, result);
+
+ // Compare against a higher version
+ free(str);
+ str = my_strdup("bcd");
+ version_destroy(compare);
+ compare = NULL;
+ status = version_createVersion(1, 2, 3, str, &compare);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ status = version_compareTo(version, compare, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK(result < 0);
+
+ // Compare againts a lower version
+ free(str);
+ str = my_strdup("abc");
+ version_destroy(compare);
+ compare = NULL;
+ status = version_createVersion(1, 1, 3, str, &compare);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+ status = version_compareTo(version, compare, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK(result > 0);
+
+ version_destroy(compare);
+ version_destroy(version);
+ free(str);
}
TEST(version, toString) {
- version_pt version = NULL;
- celix_status_t status = CELIX_SUCCESS;
- char * str;
- char *result = NULL;
-
- str = my_strdup("abc");
- status = version_createVersion(1, 2, 3, str, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
-
- status = version_toString(version, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(result != NULL);
- STRCMP_EQUAL("1.2.3.abc", result);
- free(result);
-
- version_destroy(version);
- version = NULL;
- status = version_createVersion(1, 2, 3, NULL, &version);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(version != NULL);
-
- status = version_toString(version, &result);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- CHECK_C(result != NULL);
- STRCMP_EQUAL("1.2.3", result);
-
- version_destroy(version);
- free(result);
- free(str);
+ version_pt version = NULL;
+ celix_status_t status = CELIX_SUCCESS;
+ char * str;
+ char *result = NULL;
+
+ str = my_strdup("abc");
+ status = version_createVersion(1, 2, 3, str, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+
+ status = version_toString(version, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(result != NULL);
+ STRCMP_EQUAL("1.2.3.abc", result);
+ free(result);
+
+ version_destroy(version);
+ version = NULL;
+ status = version_createVersion(1, 2, 3, NULL, &version);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(version != NULL);
+
+ status = version_toString(version, &result);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ CHECK_C(result != NULL);
+ STRCMP_EQUAL("1.2.3", result);
+
+ version_destroy(version);
+ free(result);
+ free(str);
}
TEST(version,semanticCompatibility) {
diff --git a/libs/utils/src/array_list.c b/libs/utils/src/array_list.c
index 20ad5b6..9def496 100644
--- a/libs/utils/src/array_list.c
+++ b/libs/utils/src/array_list.c
@@ -1,28 +1,29 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list.c
*
* \date Aug 4, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \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>
@@ -37,222 +38,222 @@ static bool celix_arrayList_equalsForElement(celix_array_list_t *list, celix_arr
celix_status_t arrayList_create(array_list_pt *list) {
- return arrayList_createWithEquals(arrayList_elementEquals, list);
+ return arrayList_createWithEquals(arrayList_elementEquals, list);
}
celix_status_t arrayList_createWithEquals(array_list_element_equals_pt equals, array_list_pt *list) {
- *list = celix_arrayList_create();
- if (*list != NULL) {
- (*list)->equalsDeprecated = equals;
+ *list = celix_arrayList_create();
+ if (*list != NULL) {
+ (*list)->equalsDeprecated = equals;
- }
- return CELIX_SUCCESS;
+ }
+ return CELIX_SUCCESS;
}
void arrayList_destroy(array_list_pt list) {
- celix_arrayList_destroy(list);
+ celix_arrayList_destroy(list);
}
static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool *equals) {
- *equals = (a == b);
- return CELIX_SUCCESS;
+ *equals = (a == b);
+ return CELIX_SUCCESS;
}
static bool celix_arrayList_defaultEquals(celix_array_list_entry_t a, celix_array_list_entry_t b) {
- return a.longVal == b.longVal; //just compare as long int
+ return a.longVal == b.longVal; //just compare as long int
}
static bool celix_arrayList_equalsForElement(celix_array_list_t *list, celix_array_list_entry_t a, celix_array_list_entry_t b) {
- bool equals = false;
- if (list != NULL) {
- if (list->equalsDeprecated != NULL) {
- list->equalsDeprecated(a.voidPtrVal, b.voidPtrVal, &equals);
- } else if (list->equals != NULL) {
- equals = list->equals(a, b);
- }
- }
- return equals;
+ bool equals = false;
+ if (list != NULL) {
+ if (list->equalsDeprecated != NULL) {
+ list->equalsDeprecated(a.voidPtrVal, b.voidPtrVal, &equals);
+ } else if (list->equals != NULL) {
+ equals = list->equals(a, b);
+ }
+ }
+ return equals;
}
void arrayList_trimToSize(array_list_pt list) {
- list->modCount++;
- size_t oldCapacity = list->capacity;
- if (list->size < oldCapacity) {
- celix_array_list_entry_t * newList = realloc(list->elementData, sizeof(void *) * list->size);
- list->capacity = list->size;
- list->elementData = newList;
- }
+ list->modCount++;
+ size_t oldCapacity = list->capacity;
+ if (list->size < oldCapacity) {
+ celix_array_list_entry_t * newList = realloc(list->elementData, sizeof(void *) * list->size);
+ list->capacity = list->size;
+ list->elementData = newList;
+ }
}
void arrayList_ensureCapacity(array_list_pt list, int capacity) {
- celix_array_list_entry_t *newList;
- list->modCount++;
- size_t oldCapacity = list->capacity;
- if (capacity > oldCapacity) {
- size_t newCapacity = (oldCapacity * 3) / 2 + 1;
- if (newCapacity < capacity) {
- newCapacity = capacity;
- }
- newList = realloc(list->elementData, sizeof(void *) * newCapacity);
- list->capacity = newCapacity;
- list->elementData = newList;
- }
+ celix_array_list_entry_t *newList;
+ list->modCount++;
+ size_t oldCapacity = list->capacity;
+ if (capacity > oldCapacity) {
+ size_t newCapacity = (oldCapacity * 3) / 2 + 1;
+ if (newCapacity < capacity) {
+ newCapacity = capacity;
+ }
+ newList = realloc(list->elementData, sizeof(void *) * newCapacity);
+ list->capacity = newCapacity;
+ list->elementData = newList;
+ }
}
unsigned int arrayList_size(array_list_pt list) {
- return (int)list->size;
+ return (int)list->size;
}
bool arrayList_isEmpty(array_list_pt list) {
- return list->size == 0;
+ return list->size == 0;
}
bool arrayList_contains(array_list_pt list, void * element) {
- int index = arrayList_indexOf(list, element);
- return index >= 0;
+ int index = arrayList_indexOf(list, element);
+ return index >= 0;
}
int arrayList_indexOf(array_list_pt list, void * element) {
- if (element == NULL) {
- unsigned int i = 0;
- for (i = 0; i < list->size; i++) {
- if (list->elementData[i].voidPtrVal == NULL) {
- return i;
- }
- }
- } else {
- unsigned int i = 0;
- for (i = 0; i < list->size; i++) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.voidPtrVal = element;
- bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
- if (equals) {
- return i;
- }
- }
- }
- return -1;
+ if (element == NULL) {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ if (list->elementData[i].voidPtrVal == NULL) {
+ return i;
+ }
+ }
+ } else {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.voidPtrVal = element;
+ bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
+ if (equals) {
+ return i;
+ }
+ }
+ }
+ return -1;
}
int arrayList_lastIndexOf(array_list_pt list, void * element) {
- if (element == NULL) {
- int i = 0;
- int size = (int)list->size;
- for (i = size - 1; i >= 0; i--) {
- if (list->elementData[i].voidPtrVal == NULL) {
- return (int)i;
- }
- }
- } else {
- int i = 0;
- int size = (int)list->size;
- for (i = size - 1; i >= 0; i--) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.voidPtrVal = element;
- bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
- if (equals) {
- return (int)i;
- }
- }
- }
- return -1;
+ if (element == NULL) {
+ int i = 0;
+ int size = (int)list->size;
+ for (i = size - 1; i >= 0; i--) {
+ if (list->elementData[i].voidPtrVal == NULL) {
+ return (int)i;
+ }
+ }
+ } else {
+ int i = 0;
+ int size = (int)list->size;
+ for (i = size - 1; i >= 0; i--) {
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.voidPtrVal = element;
+ bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
+ if (equals) {
+ return (int)i;
+ }
+ }
+ }
+ return -1;
}
void * arrayList_get(array_list_pt list, unsigned int index) {
- if (index >= list->size) {
- return NULL;
- }
+ if (index >= list->size) {
+ return NULL;
+ }
- return list->elementData[index].voidPtrVal;
+ return list->elementData[index].voidPtrVal;
}
void * arrayList_set(array_list_pt list, unsigned int index, void * element) {
- void * oldElement;
- if (index >= list->size) {
- return NULL;
- }
+ void * oldElement;
+ if (index >= list->size) {
+ return NULL;
+ }
- oldElement = list->elementData[index].voidPtrVal;
- memset(&list->elementData[index], 0, sizeof(celix_array_list_entry_t));
- list->elementData[index].voidPtrVal = element;
- return oldElement;
+ oldElement = list->elementData[index].voidPtrVal;
+ memset(&list->elementData[index], 0, sizeof(celix_array_list_entry_t));
+ list->elementData[index].voidPtrVal = element;
+ return oldElement;
}
bool arrayList_add(array_list_pt list, void * element) {
- arrayList_ensureCapacity(list, (int)list->size + 1);
- memset(&list->elementData[list->size], 0, sizeof(celix_array_list_entry_t));
- list->elementData[list->size++].voidPtrVal = element;
- return true;
+ arrayList_ensureCapacity(list, (int)list->size + 1);
+ memset(&list->elementData[list->size], 0, sizeof(celix_array_list_entry_t));
+ list->elementData[list->size++].voidPtrVal = element;
+ return true;
}
int arrayList_addIndex(array_list_pt list, unsigned int index, void * element) {
- size_t numMoved;
- if (index > list->size) {
- return -1;
- }
- arrayList_ensureCapacity(list, (int)list->size+1);
- numMoved = list->size - index;
- memmove(list->elementData+(index+1), list->elementData+index, sizeof(void *) * numMoved);
+ size_t numMoved;
+ if (index > list->size) {
+ return -1;
+ }
+ arrayList_ensureCapacity(list, (int)list->size+1);
+ numMoved = list->size - index;
+ memmove(list->elementData+(index+1), list->elementData+index, sizeof(void *) * numMoved);
- list->elementData[index].voidPtrVal = element;
- list->size++;
- return 0;
+ list->elementData[index].voidPtrVal = element;
+ list->size++;
+ return 0;
}
void * arrayList_remove(array_list_pt list, unsigned int index) {
- void * oldElement;
- size_t numMoved;
- if (index >= list->size) {
- return NULL;
- }
+ void * oldElement;
+ size_t numMoved;
+ if (index >= list->size) {
+ return NULL;
+ }
- list->modCount++;
- oldElement = list->elementData[index].voidPtrVal;
- numMoved = list->size - index - 1;
- memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
- memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
+ list->modCount++;
+ oldElement = list->elementData[index].voidPtrVal;
+ numMoved = list->size - index - 1;
+ memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+ memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
- return oldElement;
+ return oldElement;
}
void arrayList_fastRemove(array_list_pt list, unsigned int index) {
- size_t numMoved;
- list->modCount++;
+ size_t numMoved;
+ list->modCount++;
- numMoved = list->size - index - 1;
- memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
- memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
+ numMoved = list->size - index - 1;
+ memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+ memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
}
bool arrayList_removeElement(array_list_pt list, void * element) {
- if (element == NULL) {
- unsigned int i = 0;
- for (i = 0; i < list->size; i++) {
- if (list->elementData[i].voidPtrVal == NULL) {
- arrayList_fastRemove(list, i);
- return true;
- }
- }
- } else {
- unsigned int i = 0;
- for (i = 0; i < list->size; i++) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.voidPtrVal = element;
- bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
- if (equals) {
- arrayList_fastRemove(list, i);
- return true;
- }
- }
- }
- return false;
+ if (element == NULL) {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ if (list->elementData[i].voidPtrVal == NULL) {
+ arrayList_fastRemove(list, i);
+ return true;
+ }
+ }
+ } else {
+ unsigned int i = 0;
+ for (i = 0; i < list->size; i++) {
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.voidPtrVal = element;
+ bool equals = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
+ if (equals) {
+ arrayList_fastRemove(list, i);
+ return true;
+ }
+ }
+ }
+ return false;
}
void arrayList_clear(array_list_pt list) {
- celix_arrayList_clear(list);
+ celix_arrayList_clear(list);
}
bool arrayList_addAll(array_list_pt list, array_list_pt toAdd) {
@@ -268,83 +269,83 @@ bool arrayList_addAll(array_list_pt list, array_list_pt toAdd) {
}
array_list_pt arrayList_clone(array_list_pt list) {
- unsigned int i;
- array_list_pt new = NULL;
- arrayList_create(&new);
-// arrayList_ensureCapacity(new, list->size);
-// memcpy(new->elementData, list->elementData, list->size);
-// new->size = list->size;
-
- for (i = 0; i < arrayList_size(list); i++) {
- arrayList_add(new, arrayList_get(list, i));
- }
- new->modCount = 0;
- return new;
+ unsigned int i;
+ array_list_pt new = NULL;
+ arrayList_create(&new);
+// arrayList_ensureCapacity(new, list->size);
+// memcpy(new->elementData, list->elementData, list->size);
+// new->size = list->size;
+
+ for (i = 0; i < arrayList_size(list); i++) {
+ arrayList_add(new, arrayList_get(list, i));
+ }
+ new->modCount = 0;
+ return new;
}
array_list_iterator_pt arrayListIterator_create(array_list_pt list) {
- array_list_iterator_pt iterator = (array_list_iterator_pt) malloc(sizeof(*iterator));
+ array_list_iterator_pt iterator = (array_list_iterator_pt) malloc(sizeof(*iterator));
- iterator->lastReturned = -1;
- iterator->cursor = 0;
- iterator->list = list;
- iterator->expectedModificationCount = list->modCount;
+ iterator->lastReturned = -1;
+ iterator->cursor = 0;
+ iterator->list = list;
+ iterator->expectedModificationCount = list->modCount;
- return iterator;
+ return iterator;
}
void arrayListIterator_destroy(array_list_iterator_pt iterator) {
- iterator->lastReturned = -1;
- iterator->cursor = 0;
- iterator->expectedModificationCount = 0;
- iterator->list = NULL;
- free(iterator);
+ iterator->lastReturned = -1;
+ iterator->cursor = 0;
+ iterator->expectedModificationCount = 0;
+ iterator->list = NULL;
+ free(iterator);
}
bool arrayListIterator_hasNext(array_list_iterator_pt iterator) {
- return iterator->cursor != iterator->list->size;
+ return iterator->cursor != iterator->list->size;
}
void * arrayListIterator_next(array_list_iterator_pt iterator) {
- void * next;
- if (iterator->expectedModificationCount != iterator->list->modCount) {
- return NULL;
- }
- next = arrayList_get(iterator->list, iterator->cursor);
- iterator->lastReturned = iterator->cursor++;
- return next;
+ void * next;
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return NULL;
+ }
+ next = arrayList_get(iterator->list, iterator->cursor);
+ iterator->lastReturned = iterator->cursor++;
+ return next;
}
bool arrayListIterator_hasPrevious(array_list_iterator_pt iterator) {
- return iterator->cursor != 0;
+ return iterator->cursor != 0;
}
void * arrayListIterator_previous(array_list_iterator_pt iterator) {
- int i;
- void * previous;
- if (iterator->expectedModificationCount != iterator->list->modCount) {
- return NULL;
- }
- i = iterator->cursor - 1;
- previous = arrayList_get(iterator->list, i);
- iterator->lastReturned = iterator->cursor = i;
- return previous;
+ int i;
+ void * previous;
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return NULL;
+ }
+ i = iterator->cursor - 1;
+ previous = arrayList_get(iterator->list, i);
+ iterator->lastReturned = iterator->cursor = i;
+ return previous;
}
void arrayListIterator_remove(array_list_iterator_pt iterator) {
- if (iterator->lastReturned == -1) {
- return;
- }
- if (iterator->expectedModificationCount != iterator->list->modCount) {
- return;
- }
- if (arrayList_remove(iterator->list, iterator->lastReturned) != NULL) {
- if (iterator->lastReturned < iterator->cursor) {
- iterator->cursor--;
- }
- iterator->lastReturned = -1;
- iterator->expectedModificationCount = iterator->list->modCount;
- }
+ if (iterator->lastReturned == -1) {
+ return;
+ }
+ if (iterator->expectedModificationCount != iterator->list->modCount) {
+ return;
+ }
+ if (arrayList_remove(iterator->list, iterator->lastReturned) != NULL) {
+ if (iterator->lastReturned < iterator->cursor) {
+ iterator->cursor--;
+ }
+ iterator->lastReturned = -1;
+ iterator->expectedModificationCount = iterator->list->modCount;
+ }
}
@@ -357,40 +358,40 @@ void arrayListIterator_remove(array_list_iterator_pt iterator) {
**********************************************************************************************************************/
celix_array_list_t* celix_arrayList_create() {
- return celix_arrayList_createWithEquals(celix_arrayList_defaultEquals);
+ return celix_arrayList_createWithEquals(celix_arrayList_defaultEquals);
}
celix_array_list_t* celix_arrayList_createWithEquals(celix_arrayList_equals_fp equals) {
- array_list_t *list = calloc(1, sizeof(*list));
- if (list != NULL) {
- list->capacity = 10;
- list->elementData = malloc(sizeof(void*) * list->capacity);
- list->equals = equals;
- }
- return list;
+ array_list_t *list = calloc(1, sizeof(*list));
+ if (list != NULL) {
+ list->capacity = 10;
+ list->elementData = malloc(sizeof(void*) * list->capacity);
+ list->equals = equals;
+ }
+ return list;
}
void celix_arrayList_destroy(celix_array_list_t *list) {
- list->size = 0;
- free(list->elementData);
- free(list);
+ list->size = 0;
+ free(list->elementData);
+ free(list);
}
int celix_arrayList_size(const celix_array_list_t *list) {
- return list->size;
+ return list->size;
}
static celix_array_list_entry_t arrayList_getEntry(const celix_array_list_t *list, int index) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- if (index < list->size) {
- entry = list->elementData[index];
- }
- return entry;
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ if (index < list->size) {
+ entry = list->elementData[index];
+ }
+ return entry;
}
void* celix_arrayList_get(const celix_array_list_t *list, int index) {
- return arrayList_getEntry(list, index).voidPtrVal;
+ return arrayList_getEntry(list, index).voidPtrVal;
}
int celix_arrayList_getInt(const celix_array_list_t *list, int index) { return arrayList_getEntry(list, index).intVal; }
@@ -403,163 +404,163 @@ bool celix_arrayList_getBool(const celix_array_list_t *list, int index) { return
size_t celix_arrayList_getSize(const celix_array_list_t *list, int index) { return arrayList_getEntry(list, index).sizeVal; }
static void arrayList_addEntry(celix_array_list_t *list, celix_array_list_entry_t entry) {
- arrayList_ensureCapacity(list, (int)list->size + 1);
- memset(&list->elementData[list->size], 0, sizeof(entry));
- list->elementData[list->size++] = entry;
+ arrayList_ensureCapacity(list, (int)list->size + 1);
+ memset(&list->elementData[list->size], 0, sizeof(entry));
+ list->elementData[list->size++] = entry;
}
void celix_arrayList_add(celix_array_list_t *list, void * element) {
- celix_array_list_entry_t entry = { .voidPtrVal = element };
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry = { .voidPtrVal = element };
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addInt(celix_array_list_t *list, int val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.intVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.intVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addLong(celix_array_list_t *list, long val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.longVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.longVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addUInt(celix_array_list_t *list, unsigned int val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.uintVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.uintVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addULong(celix_array_list_t *list, unsigned long val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.ulongVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.ulongVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addDouble(celix_array_list_t *list, double val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.doubleVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.doubleVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addFloat(celix_array_list_t *list, float val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.floatVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.floatVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addBool(celix_array_list_t *list, bool val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.boolVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.boolVal = val;
+ arrayList_addEntry(list, entry);
}
void celix_arrayList_addSize(celix_array_list_t *list, size_t val) {
- celix_array_list_entry_t entry;
- memset(&entry, 0, sizeof(entry));
- entry.sizeVal = val;
- arrayList_addEntry(list, entry);
+ celix_array_list_entry_t entry;
+ memset(&entry, 0, sizeof(entry));
+ entry.sizeVal = val;
+ arrayList_addEntry(list, entry);
}
int celix_arrayList_indexOf(celix_array_list_t *list, celix_array_list_entry_t entry) {
- size_t size = celix_arrayList_size(list);
- int i;
- int index = -1;
- for (i = 0 ; i < size ; ++i) {
- bool eq = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
- if (eq) {
- index = i;
- break;
- }
- }
- return index;
+ size_t size = celix_arrayList_size(list);
+ int i;
+ int index = -1;
+ for (i = 0 ; i < size ; ++i) {
+ bool eq = celix_arrayList_equalsForElement(list, entry, list->elementData[i]);
+ if (eq) {
+ index = i;
+ break;
+ }
+ }
+ return index;
}
void celix_arrayList_removeAt(celix_array_list_t *list, int index) {
- if (index >= 0 && index < list->size) {
- list->modCount++;
- size_t numMoved = list->size - index - 1;
- memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
- memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
- }
+ if (index >= 0 && index < list->size) {
+ list->modCount++;
+ size_t numMoved = list->size - index - 1;
+ memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+ memset(&list->elementData[--list->size], 0, sizeof(celix_array_list_entry_t));
+ }
}
void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entry_t entry) {
- int index = celix_arrayList_indexOf(list, entry);
- celix_arrayList_removeAt(list, index);
+ int index = celix_arrayList_indexOf(list, entry);
+ celix_arrayList_removeAt(list, index);
}
void celix_arrayList_remove(celix_array_list_t *list, void *ptr) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.voidPtrVal = ptr;
- celix_arrayList_removeEntry(list, entry);
+ entry.voidPtrVal = ptr;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeInt(celix_array_list_t *list, int val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.intVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.intVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeLong(celix_array_list_t *list, long val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.longVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.longVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeUInt(celix_array_list_t *list, unsigned int val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.uintVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.uintVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeULong(celix_array_list_t *list, unsigned long val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.ulongVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.ulongVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeFloat(celix_array_list_t *list, float val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.floatVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.floatVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeDouble(celix_array_list_t *list, double val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.doubleVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.doubleVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeBool(celix_array_list_t *list, bool val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.boolVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.boolVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_removeSize(celix_array_list_t *list, size_t val) {
- celix_array_list_entry_t entry;
+ celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
- entry.sizeVal = val;
- celix_arrayList_removeEntry(list, entry);
+ entry.sizeVal = val;
+ celix_arrayList_removeEntry(list, entry);
}
void celix_arrayList_clear(celix_array_list_t *list) {
- unsigned int i;
- list->modCount++;
-
- for (i = 0; i < list->size; i++) {
- // free(list->elementData[i]);
- memset(&list->elementData[i], 0, sizeof(celix_array_list_entry_t));
- }
- list->size = 0;
+ unsigned int i;
+ list->modCount++;
+
+ for (i = 0; i < list->size; i++) {
+ // free(list->elementData[i]);
+ memset(&list->elementData[i], 0, sizeof(celix_array_list_entry_t));
+ }
+ list->size = 0;
}
diff --git a/libs/utils/src/array_list_private.h b/libs/utils/src/array_list_private.h
index df37354..89d1d74 100644
--- a/libs/utils/src/array_list_private.h
+++ b/libs/utils/src/array_list_private.h
@@ -1,27 +1,27 @@
/**
- *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
+ * 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
+ * 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.
+ * 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.
*/
/*
* array_list_private.h
*
* \date Aug 4, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
+ * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ * \copyright Apache License, Version 2.0
*/
#ifndef array_list_t_PRIVATE_H_
@@ -30,21 +30,21 @@
#include "array_list.h"
struct celix_array_list {
- celix_array_list_entry_t* elementData;
- size_t size;
- size_t capacity;
+ celix_array_list_entry_t* elementData;
+ size_t size;
+ size_t capacity;
- unsigned int modCount;
+ unsigned int modCount;
- array_list_element_equals_pt equalsDeprecated;
- celix_arrayList_equals_fp equals;
+ array_list_element_equals_pt equalsDeprecated;
+ celix_arrayList_equals_fp equals;
};
struct celix_array_list_iterator {
- array_list_pt list;
- unsigned int cursor;
- int lastReturned;
- unsigned int expectedModificationCount;
+ array_list_pt list;
+ unsigned int cursor;
+ int lastReturned;
+ unsigned int expectedModificationCount;
};
void * arrayList_remove(array_list_pt list, unsigned int index);
diff --git a/libs/utils/src/celix_threads.c b/libs/utils/src/celix_threads.c
index f01d258..58a8528 100644
--- a/libs/utils/src/celix_threads.c
+++ b/libs/utils/src/celix_threads.c
@@ -1,20 +1,20 @@
/**
- *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
+ * 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
+ * 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.
+ * 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_threads.c
@@ -33,23 +33,23 @@
celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data) {
celix_status_t status = CELIX_SUCCESS;
- if (pthread_create(&(*new_thread).thread, attr, func, data) != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
- else {
- (*new_thread).threadInitialized = true;
- }
+ if (pthread_create(&(*new_thread).thread, attr, func, data) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
+ else {
+ (*new_thread).threadInitialized = true;
+ }
- return status;
+ return status;
}
#if defined(_GNU_SOURCE) && defined(__linux__)
void celixThread_setName(celix_thread_t *thread, const char *threadName) {
- pthread_setname_np(thread->thread, threadName);
+ pthread_setname_np(thread->thread, threadName);
}
#else
void celixThread_setName(celix_thread_t *thread __attribute__((unused)), const char *threadName __attribute__((unused))) {
- //nop
+ //nop
}
#endif
@@ -63,14 +63,14 @@ celix_status_t celixThread_detach(celix_thread_t thread) {
}
celix_status_t celixThread_join(celix_thread_t thread, void **retVal) {
- celix_status_t status = CELIX_SUCCESS;
+ celix_status_t status = CELIX_SUCCESS;
- if (pthread_join(thread.thread, retVal) != 0) {
- status = CELIX_BUNDLE_EXCEPTION;
- }
+ if (pthread_join(thread.thread, retVal) != 0) {
+ status = CELIX_BUNDLE_EXCEPTION;
+ }
// #TODO make thread a pointer? Now this statement has no effect
- // thread.threadInitialized = false;
+ // thread.threadInitialized = false;
return status;
}
@@ -80,12 +80,12 @@ celix_status_t celixThread_kill(celix_thread_t thread, int sig) {
}
celix_thread_t celixThread_self() {
- celix_thread_t thread;
+ celix_thread_t thread;
- thread.thread = pthread_self();
- thread.threadInitialized = true;
+ thread.thread = pthread_self();
+ thread.threadInitialized = true;
- return thread;
+ return thread;
}
int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2) {
@@ -114,33 +114,33 @@ celix_status_t celixThreadMutex_unlock(celix_thread_mutex_t *mutex) {
}
celix_status_t celixThreadMutexAttr_create(celix_thread_mutexattr_t *attr) {
- return pthread_mutexattr_init(attr);
+ return pthread_mutexattr_init(attr);
}
celix_status_t celixThreadMutexAttr_destroy(celix_thread_mutexattr_t *attr) {
- return pthread_mutexattr_destroy(attr);
+ return pthread_mutexattr_destroy(attr);
}
celix_status_t celixThreadMutexAttr_settype(celix_thread_mutexattr_t *attr, int type) {
- celix_status_t status;
- switch(type) {
- case CELIX_THREAD_MUTEX_NORMAL :
... 4917 lines suppressed ...