-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iothub_client_init/deinit implementation
- Loading branch information
Showing
9 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#ifndef IOTHUB_H | ||
#define IOTHUB_H | ||
|
||
#include "azure_c_shared_utility/umock_c_prod.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#else | ||
#endif | ||
/** | ||
* @brief IoTHubClient_Init Initializes the IoTHub Client System. | ||
* | ||
* @param client_param Reserved for future use. | ||
* | ||
* @return int zero upon success, any other value upon failure. | ||
*/ | ||
MOCKABLE_FUNCTION(, int, IoTHub_Init); | ||
|
||
/** | ||
* @brief IoTHubClient_Deinit Frees resources initialized in the IoTHubClient_Init function call. | ||
* | ||
*/ | ||
MOCKABLE_FUNCTION(, void, IoTHub_Deinit); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* IOTHUB_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include <stdlib.h> | ||
|
||
#include "azure_c_shared_utility/platform.h" | ||
#include "azure_c_shared_utility/xlogging.h" | ||
#include "azure_c_shared_utility/macro_utils.h" | ||
#include "iothub.h" | ||
|
||
int IoTHub_Init() | ||
{ | ||
int result; | ||
if (platform_init() != 0) | ||
{ | ||
LogError("Platform initialization failed"); | ||
result = __FAILURE__; | ||
} | ||
else | ||
{ | ||
result = 0; | ||
} | ||
return result; | ||
} | ||
|
||
void IoTHub_Deinit() | ||
{ | ||
platform_deinit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#Copyright (c) Microsoft. All rights reserved. | ||
#Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
compileAsC11() | ||
|
||
set(theseTestsName iothub_ut) | ||
|
||
set(${theseTestsName}_test_files | ||
${theseTestsName}.c | ||
) | ||
|
||
include_directories(${SHARED_UTIL_REAL_TEST_FOLDER}) | ||
|
||
set(${theseTestsName}_c_files | ||
../../src/iothub.c | ||
) | ||
|
||
set(${theseTestsName}_h_files | ||
) | ||
|
||
build_c_test_artifacts(${theseTestsName} ON "tests/azure_iothub_client_tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#ifdef __cplusplus | ||
#include <cstdlib> | ||
#include <cstddef> | ||
#else | ||
#include <stdlib.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#endif | ||
|
||
#include "testrunnerswitcher.h" | ||
#include "azure_c_shared_utility/macro_utils.h" | ||
|
||
#include "umock_c.h" | ||
#include "umock_c_negative_tests.h" | ||
#include "umocktypes_charptr.h" | ||
|
||
#define ENABLE_MOCKS | ||
#include "azure_c_shared_utility/platform.h" | ||
#undef ENABLE_MOCKS | ||
|
||
#include "iothub.h" | ||
|
||
static TEST_MUTEX_HANDLE test_serialize_mutex; | ||
static TEST_MUTEX_HANDLE g_dllByDll; | ||
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) | ||
|
||
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) | ||
{ | ||
char temp_str[256]; | ||
(void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code)); | ||
ASSERT_FAIL(temp_str); | ||
} | ||
|
||
BEGIN_TEST_SUITE(iothub_ut) | ||
|
||
TEST_SUITE_INITIALIZE(suite_init) | ||
{ | ||
TEST_INITIALIZE_MEMORY_DEBUG(g_dllByDll); | ||
|
||
test_serialize_mutex = TEST_MUTEX_CREATE(); | ||
ASSERT_IS_NOT_NULL(test_serialize_mutex); | ||
|
||
umock_c_init(on_umock_c_error); | ||
|
||
REGISTER_GLOBAL_MOCK_RETURN(platform_init, 0); | ||
REGISTER_GLOBAL_MOCK_FAIL_RETURN(platform_init, __LINE__); | ||
} | ||
|
||
TEST_SUITE_CLEANUP(suite_cleanup) | ||
{ | ||
umock_c_deinit(); | ||
TEST_MUTEX_DESTROY(test_serialize_mutex); | ||
TEST_DEINITIALIZE_MEMORY_DEBUG(g_dllByDll); | ||
} | ||
|
||
TEST_FUNCTION(IoTHub_Init_succeed) | ||
{ | ||
//arrange | ||
STRICT_EXPECTED_CALL(platform_init()); | ||
|
||
//act | ||
int result = IoTHub_Init(); | ||
|
||
//assert | ||
ASSERT_ARE_EQUAL(int, 0, result); | ||
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); | ||
} | ||
|
||
TEST_FUNCTION(IoTHub_Init_fail) | ||
{ | ||
//arrange | ||
STRICT_EXPECTED_CALL(platform_init()); | ||
|
||
//act | ||
int result = IoTHub_Init(); | ||
|
||
//assert | ||
ASSERT_ARE_EQUAL(int, 0, result); | ||
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); | ||
} | ||
|
||
TEST_FUNCTION(IoTHub_Deinit_succeed) | ||
{ | ||
//arrange | ||
STRICT_EXPECTED_CALL(platform_deinit()); | ||
|
||
//act | ||
IoTHub_Deinit(); | ||
|
||
//assert | ||
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); | ||
} | ||
|
||
END_TEST_SUITE(iothub_ut) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "testrunnerswitcher.h" | ||
|
||
int main(void) | ||
{ | ||
size_t failedTestCount = 0; | ||
RUN_TEST_SUITE(iothub_ut, failedTestCount); | ||
return failedTestCount; | ||
} |