Skip to content

Commit 33ff8bf

Browse files
committed
[wip] adding unit tests
1 parent 1e68e1b commit 33ff8bf

File tree

10 files changed

+182
-2
lines changed

10 files changed

+182
-2
lines changed

services/inc/ncp_fw_update.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "hal_platform.h"
2121
#include "system_tick_hal.h"
22-
#include "core_hal.h"
2322
#include "system_defs.h"
2423
#include "system_mode.h"
2524
#include "system_network.h"
@@ -196,6 +195,7 @@ class SaraNcpFwUpdate {
196195
void logSaraNcpFwUpdateData(SaraNcpFwUpdateData& data);
197196
};
198197

198+
#ifndef UNIT_TEST
199199
class NcpFwUpdateDiagnostics: public AbstractUnsignedIntegerDiagnosticData {
200200
public:
201201
NcpFwUpdateDiagnostics() :
@@ -207,6 +207,7 @@ class NcpFwUpdateDiagnostics: public AbstractUnsignedIntegerDiagnosticData {
207207
return 0; // OK
208208
}
209209
};
210+
#endif // UNIT_TEST
210211

211212
} // namespace services
212213

services/src/ncp_fw_update.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ LOG_SOURCE_CATEGORY(SARA_NCP_FW_UPDATE_LOG_CATEGORY);
3535

3636
#include "check.h"
3737
#include "delay_hal.h"
38-
#include "platform_headers.h"
3938
#include "system_network.h"
4039

4140
// Change to 0 for debugging faster

test/unit_tests/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ Build and run the tests and coverage:
2121
```bash
2222
make all test coverage
2323
```
24+
25+
26+
MacOSX
27+
------
28+
29+
Github issue: https://github.com/Homebrew/homebrew-core/issues/67427
30+
31+
You may run into an error `ld: library not found for -licudata` and will need to export the following before running `make`
32+
33+
`export LIBRARY_PATH=${LIBRARY_PATH}:/usr/local/opt/icu4c/lib`

test/unit_tests/services/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ add_executable( ${target_name}
77
${TEST_DIR}/util/random.cpp
88
${DEVICE_OS_DIR}/services/src/simple_file_storage.cpp
99
${DEVICE_OS_DIR}/services/src/str_util.cpp
10+
${DEVICE_OS_DIR}/services/src/ncp_fw_update.cpp
11+
ncp_fw_update.cpp
1012
simple_file_storage.cpp
1113
str_util.cpp
1214
varint.cpp
@@ -17,6 +19,7 @@ add_executable( ${target_name}
1719
target_compile_definitions( ${target_name}
1820
PRIVATE PLATFORM_ID=3
1921
PRIVATE HAL_PLATFORM_FILESYSTEM=1
22+
PRIVATE HAL_PLATFORM_NCP_FW_UPDATE=1
2023
)
2124

2225
# Set compiler flags specific to target
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "ncp_fw_update.h"
19+
// #include "system_error.h"
20+
21+
// #include "mock/filesystem.h"
22+
// #include "mock/ncp_fw_update.h"
23+
// #include "util/random.h"
24+
25+
#include <catch2/catch.hpp>
26+
#include <hippomocks.h>
27+
28+
#include <string>
29+
// #include <unordered_map>
30+
31+
32+
using namespace particle;
33+
34+
TEST_CASE("SaraNcpFwUpdate") {
35+
// MockRepository mocks;
36+
SECTION("init()") {
37+
SECTION("initialize callbacks") {
38+
SaraNcpFwUpdateCallbacks saraNcpFwUpdateCallbacks;
39+
memset(&saraNcpFwUpdateCallbacks, 0, sizeof(saraNcpFwUpdateCallbacks));
40+
// saraNcpFwUpdateCallbacks.size = sizeof(saraNcpFwUpdateCallbacks);
41+
// saraNcpFwUpdateCallbacks.system_get_flag = system_get_flag;
42+
// saraNcpFwUpdateCallbacks.spark_cloud_flag_connected = spark_cloud_flag_connected;
43+
// saraNcpFwUpdateCallbacks.spark_cloud_flag_connect = spark_cloud_flag_connect;
44+
// saraNcpFwUpdateCallbacks.spark_cloud_flag_disconnect = spark_cloud_flag_disconnect;
45+
// saraNcpFwUpdateCallbacks.publishEvent = publishEvent;
46+
// saraNcpFwUpdateCallbacks.system_mode = system_mode;
47+
// services::SaraNcpFwUpdate::instance()->init(saraNcpFwUpdateCallbacks);
48+
// CHECK(strcmp(n.init(), "path/to/file") == 0);
49+
}
50+
}
51+
}

test/unit_tests/stub/module_info.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once
19+
20+
typedef struct module_store_t {
21+
} module_store_t;
22+
23+
typedef struct module_info_t {
24+
} module_info_t;
25+
26+
typedef struct module_info_crc_t {
27+
} module_info_crc_t;
28+
29+
typedef struct module_info_suffix_t {
30+
} module_info_suffix_t;
31+
32+
typedef struct module_function_t {
33+
} module_function_t;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once
19+
20+
typedef struct AtResponseReader {
21+
} AtResponseReader;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once

test/unit_tests/stub/system_mode.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once
19+
20+
typedef enum
21+
{
22+
DEFAULT=0, AUTOMATIC = 1, SEMI_AUTOMATIC = 2, MANUAL = 3, SAFE_MODE=4
23+
} System_Mode_TypeDef;
24+
25+
void set_system_mode(System_Mode_TypeDef mode);
26+
System_Mode_TypeDef system_mode();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2021 Particle Industries, Inc. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once

0 commit comments

Comments
 (0)