Skip to content

Commit fe1d458

Browse files
committed
simplify
1 parent 2938bd0 commit fe1d458

34 files changed

+508
-774
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ while ! nc -z localhost $mockPort >/dev/null 2>&1; do
8686
sleep 1
8787
done
8888

89-
echo "Starting cpp_test with -mock and -auto flags"
89+
echo "Starting '$(basename "$testExe") --mock --auto'"
9090
cd "$(dirname "$testExe")"
91-
"./$(basename "$testExe")" -mock -auto
91+
"./$(basename "$testExe")" --mock --auto
9292
exitCode=$?
9393

9494
kill-rec $mock_pid

.github/workflows/ci.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ jobs:
269269
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
270270
--test-exe /workspace/build/test/ctApp
271271
272-
cpp_demo_tests:
272+
api_test_app:
273273
permissions:
274274
contents: read
275275
packages: read
@@ -292,7 +292,7 @@ jobs:
292292
name: build-dir
293293
path: ${{ github.workspace }}/build
294294

295-
- name: Build api_test_app standalone
295+
- name: Build api-test-app standalone
296296
run: |
297297
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
298298
bash -c " \
@@ -314,16 +314,13 @@ jobs:
314314
path: ${{ env.MOCK_PATH }}
315315
key: ${{ runner.os }}-mock-${{ steps.setup-mock.outputs.deps_cache_key }}
316316

317-
- name: Run Demo with mock server
317+
- name: Run API-TEST-APP with mock server
318318
run: |
319-
chmod +x ${{ github.workspace }}/test/api_test_app/build/api_test_app
319+
chmod +x ${{ github.workspace }}/test/api_test_app/build/api-test-app
320320
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace -v ${{ env.MOCK_PATH }}:/mock ${{ needs.build_docker.outputs.image_tag }} \
321-
./.github/scripts/run-cpp-test.sh \
321+
./.github/scripts/run-api-test-app.sh \
322322
--mock /mock \
323323
--config /workspace/.github/mock-firebolt/config.json \
324324
--openrpc /workspace/docs/openrpc/the-spec/firebolt-open-rpc.json \
325325
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
326-
--test-exe /workspace/test/api_test_app/build/api_test_app
327-
328-
# Removed artifact upload step for api_test_app binary as per PR feedback
329-
326+
--test-exe /workspace/test/api_test_app/build/api-test-app

test/api_test_app/CMakeLists.txt

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
if (NOT CMAKE_PROJECT_NAME)
1818
cmake_minimum_required(VERSION 3.10)
19-
project(api_test_app CXX)
19+
project(api-test-app CXX)
2020

2121
# Read SYSROOT_PATH from environment if not set as CMake variable
2222
if (NOT SYSROOT_PATH AND DEFINED ENV{SYSROOT_PATH})
@@ -30,7 +30,7 @@ if (NOT CMAKE_PROJECT_NAME)
3030

3131
# Add paths for finding installed packages
3232
if (SYSROOT_PATH)
33-
list(APPEND CMAKE_PREFIX_PATH
33+
list(APPEND CMAKE_PREFIX_PATH
3434
"${SYSROOT_PATH}/usr/lib/cmake"
3535
"${SYSROOT_PATH}/usr/share/cmake"
3636
)
@@ -40,117 +40,52 @@ if (NOT CMAKE_PROJECT_NAME)
4040
"${SYSROOT_PATH}/tools/cmake"
4141
)
4242
endif()
43-
44-
# Add standard system paths for finding packages
45-
list(APPEND CMAKE_PREFIX_PATH
46-
"/usr/local"
47-
"/usr"
48-
)
43+
4944
endif ()
5045

51-
set(API_TEST_APP api_test_app)
46+
set(API_TEST_APP api-test-app)
5247

5348
message("Setup ${API_TEST_APP}")
5449

5550
add_compile_options(-Wall -Wextra -Wpedantic)
5651

57-
# Generate header file with embedded JSON content
58-
file(READ "../../docs/openrpc/the-spec/firebolt-open-rpc.json" JSON_CONTENT)
59-
configure_file(
60-
cpp/firebolt-open-rpc.json.in
61-
"${CMAKE_BINARY_DIR}/generated/firebolt-open-rpc_json.h"
62-
@ONLY
63-
)
64-
6552
file(GLOB SOURCES CONFIGURE_DEPENDS cpp/*.cpp)
6653

6754
add_executable(${API_TEST_APP}
6855
main.cpp
56+
utils.cpp
6957
${SOURCES}
7058
)
7159

60+
find_package(FireboltTransport CONFIG REQUIRED)
61+
7262
if (ENABLE_DEMO_APP)
73-
# Building as part of the main project - dependencies already available
74-
if(TARGET nlohmann_json_schema_validator::validator)
75-
set(NLOHMANN_VALIDATOR_TARGET nlohmann_json_schema_validator::validator)
76-
else()
77-
set(NLOHMANN_VALIDATOR_TARGET nlohmann_json_schema_validator)
78-
endif()
79-
if(TARGET CURL::libcurl)
80-
set(CURL_TARGET CURL::libcurl)
81-
else()
82-
set(CURL_TARGET curl)
83-
endif()
84-
if(TARGET Threads::Threads)
85-
set(THREADS_TARGET Threads::Threads)
86-
else()
87-
set(THREADS_TARGET pthread)
88-
endif()
8963
target_link_libraries(${API_TEST_APP}
9064
PRIVATE
9165
FireboltClient
92-
nlohmann_json::nlohmann_json
93-
${NLOHMANN_VALIDATOR_TARGET}
94-
${CURL_TARGET}
95-
${THREADS_TARGET}
9666
)
97-
set(SOURCE_ROOT ${CMAKE_SOURCE_DIR})
98-
target_link_directories(${API_TEST_APP} PRIVATE $ENV{SYSROOT_PATH}/usr/lib)
9967
else()
100-
# Building standalone - find all installed dependencies
101-
find_package(FireboltTransport CONFIG REQUIRED)
10268
find_package(FireboltClient CONFIG REQUIRED)
103-
find_package(nlohmann_json REQUIRED)
104-
find_package(nlohmann_json_schema_validator CONFIG REQUIRED)
105-
find_package(CURL REQUIRED)
106-
find_package(Threads REQUIRED)
107-
if(TARGET nlohmann_json_schema_validator::validator)
108-
set(NLOHMANN_VALIDATOR_TARGET nlohmann_json_schema_validator::validator)
109-
else()
110-
set(NLOHMANN_VALIDATOR_TARGET nlohmann_json_schema_validator)
111-
endif()
112-
if(TARGET CURL::libcurl)
113-
set(CURL_TARGET CURL::libcurl)
114-
else()
115-
set(CURL_TARGET curl)
116-
endif()
117-
if(TARGET Threads::Threads)
118-
set(THREADS_TARGET Threads::Threads)
119-
else()
120-
set(THREADS_TARGET pthread)
121-
endif()
12269
target_link_libraries(${API_TEST_APP}
12370
PRIVATE
12471
FireboltTransport::FireboltTransport
12572
FireboltClient::FireboltClient
126-
nlohmann_json::nlohmann_json
127-
${NLOHMANN_VALIDATOR_TARGET}
128-
${CURL_TARGET}
129-
${THREADS_TARGET}
13073
)
131-
set(SOURCE_ROOT ${CMAKE_SOURCE_DIR}/../..)
132-
endif ()
74+
endif()
13375

13476
target_include_directories(${API_TEST_APP}
13577
PRIVATE
136-
137-
$<BUILD_INTERFACE:${SOURCE_ROOT}/include/>
138-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src/>
139-
$<BUILD_INTERFACE:${SOURCE_ROOT}/test/>
140-
$<BUILD_INTERFACE:${SOURCE_ROOT}/src/>
141-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated>
78+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../src>
79+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
80+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp>
14281
)
14382

144-
add_compile_definitions(UT_OPEN_RPC_FILE="firebolt-open-rpc.json")
145-
14683
set_target_properties(${API_TEST_APP} PROPERTIES
14784
CXX_STANDARD 17
14885
CXX_STANDARD_REQUIRED YES
149-
BUILD_RPATH "${CMAKE_BINARY_DIR}/src"
150-
INSTALL_RPATH "$ORIGIN/../src"
15186
)
15287

15388
install(
15489
TARGETS ${API_TEST_APP}
15590
DESTINATION bin
156-
)
91+
)

test/api_test_app/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ bdir="build"
2222
run=true
2323
buildType="Debug"
2424

25-
while [[ ! -z $1 ]]; do
25+
while [[ -n $1 ]]; do
2626
case $1 in
2727
--clean) rm -rf $bdir;;
2828
--just-run)
2929
export LD_LIBRARY_PATH=$bdir/src:$SYSROOT_PATH/usr/lib:$LD_LIBRARY_PATH
30-
$bdir/api_test_app -mock
30+
$bdir/api_test_app --mock
3131
exit;;
3232
--no-run) run=false;;
3333
--release) buildType="Release";;
@@ -37,7 +37,7 @@ while [[ ! -z $1 ]]; do
3737
esac; shift
3838
done
3939

40-
[[ ! -z $SYSROOT_PATH ]] || { echo "SYSROOT_PATH not set" >/dev/stderr; exit 1; }
40+
[[ -n $SYSROOT_PATH ]] || { echo "SYSROOT_PATH not set" >/dev/stderr; exit 1; }
4141
[[ -e $SYSROOT_PATH ]] || { echo "SYSROOT_PATH not exist ($SYSROOT_PATH)" >/dev/stderr; exit 1; }
4242

4343
if [[ ! -e "$bdir" ]]; then
@@ -60,6 +60,6 @@ cmake --build $bdir
6060

6161
if $run; then
6262
export LD_LIBRARY_PATH=$bdir/src:$SYSROOT_PATH/usr/lib:$LD_LIBRARY_PATH
63-
$bdir/api_test_app -mock
63+
$bdir/api_test_app --mock
6464
fi
6565

test/api_test_app/cpp/accessibilityDemo.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,60 @@
1717
*/
1818

1919
#include "accessibilityDemo.h"
20+
#include <firebolt/firebolt.h>
2021
#include <iostream>
2122
#include <string>
2223
#include <vector>
2324

24-
#include "json_types/jsondata_device_types.h"
25-
2625
using namespace Firebolt;
2726
using namespace Firebolt::Accessibility;
2827

2928
AccessibilityDemo::AccessibilityDemo()
3029
: FireboltDemoBase()
3130
{
32-
methodsFromRpc("Accessibility");
31+
methods_.push_back("Accessibility.audioDescription");
32+
methods_.push_back("Accessibility.closedCaptionsSettings");
33+
methods_.push_back("Accessibility.highContrastUI");
34+
methods_.push_back("Accessibility.voiceGuidanceSettings");
3335
}
3436

35-
void AccessibilityDemo::runOption(const int index)
37+
void AccessibilityDemo::runOption(const std::string& method)
3638
{
37-
std::string key = itemDescriptions_[index].name;
38-
39-
std::cout << "Running Accessibility method: " << key << std::endl;
39+
std::cout << "Running Accessibility method: " << method << std::endl;
4040

41-
if (key == "Accessibility.closedCaptionsSettings")
41+
if (method == "Accessibility.closedCaptionsSettings")
4242
{
4343
Result<ClosedCaptionsSettings> r =
4444
Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptionsSettings();
45-
if (validateResult(r))
45+
if (succeed(r))
4646
{
47-
ClosedCaptionsSettings settings = r.value();
48-
std::cout << "Closed Captions Settings - Enabled: " << (settings.enabled ? "true" : "false") << std::endl;
47+
std::cout << "Closed Captions Settings - Enabled: " << (r->enabled ? "true" : "false") << std::endl;
4948
}
5049
}
51-
else if (key == "Accessibility.audioDescription")
50+
else if (method == "Accessibility.audioDescription")
5251
{
5352
Result<bool> r = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().audioDescription();
54-
if (validateResult(r))
53+
if (succeed(r))
5554
{
56-
bool enabled = r.value();
57-
std::cout << "Audio Description Enabled: " << (enabled ? "true" : "false") << std::endl;
55+
std::cout << "Audio Description Enabled: " << (*r ? "true" : "false") << std::endl;
5856
}
5957
}
60-
else if (key == "Accessibility.highContrastUI")
58+
else if (method == "Accessibility.highContrastUI")
6159
{
6260
Result<bool> r = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().highContrastUI();
63-
if (validateResult(r))
61+
if (succeed(r))
6462
{
65-
bool enabled = r.value();
66-
67-
std::cout << "High Contrast UI Enabled: " << (enabled ? "true" : "false") << std::endl;
63+
std::cout << "High Contrast UI Enabled: " << (*r ? "true" : "false") << std::endl;
6864
}
6965
}
70-
else if (key == "Accessibility.voiceGuidanceSettings")
66+
else if (method == "Accessibility.voiceGuidanceSettings")
7167
{
7268
Result<VoiceGuidanceSettings> r =
7369
Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().voiceGuidanceSettings();
74-
if (validateResult(r))
70+
if (succeed(r))
7571
{
76-
VoiceGuidanceSettings settings = r.value();
77-
std::cout << "Voice Guidance Settings - Enabled: " << (settings.enabled ? "true" : "false")
78-
<< ", Rate: " << settings.rate << std::endl;
72+
std::cout << "Voice Guidance Settings - Enabled: " << (r->enabled ? "true" : "false")
73+
<< ", Rate: " << r->rate << std::endl;
7974
}
8075
}
81-
}
76+
}

test/api_test_app/cpp/accessibilityDemo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
#include "fireboltDemoBase.h"
2222
#include <string>
23-
#include <vector>
2423

2524
class AccessibilityDemo : public FireboltDemoBase
2625
{
2726
public:
2827
AccessibilityDemo();
2928
~AccessibilityDemo() = default;
30-
void runOption(const int index);
29+
void runOption(const std::string& method) override;
3130
};

test/api_test_app/cpp/advertisingDemo.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "advertisingDemo.h"
20+
#include <firebolt/firebolt.h>
2021
#include <iostream>
2122
#include <string>
2223
#include <vector>
@@ -27,22 +28,19 @@ using namespace Firebolt::Advertising;
2728
AdvertisingDemo::AdvertisingDemo()
2829
: FireboltDemoBase()
2930
{
30-
methodsFromRpc("Advertising");
31+
methods_.push_back("Advertising.advertisingId");
3132
}
3233

33-
void AdvertisingDemo::runOption(const int index)
34+
void AdvertisingDemo::runOption(const std::string& method)
3435
{
35-
std::string key = itemDescriptions_[index].name;
36-
37-
if (key == "Advertising.advertisingId")
36+
if (method == "Advertising.advertisingId")
3837
{
39-
Result<Ifa> result = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().advertisingId();
40-
if (validateResult(result))
38+
Result<Ifa> r = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().advertisingId();
39+
if (succeed(r))
4140
{
42-
Ifa ifa = result.value();
43-
std::cout << "IFA: " << ifa.ifa << std::endl;
44-
std::cout << "IFA Type: " << ifa.ifa_type << std::endl;
45-
std::cout << "LMT: " << ifa.lmt << std::endl;
41+
std::cout << "IFA: " << r->ifa << std::endl;
42+
std::cout << "IFA Type: " << r->ifa_type << std::endl;
43+
std::cout << "LMT: " << r->lmt << std::endl;
4644
}
4745
}
4846
}

test/api_test_app/cpp/advertisingDemo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
#include "fireboltDemoBase.h"
2222
#include <string>
23-
#include <vector>
2423

2524
class AdvertisingDemo : public FireboltDemoBase
2625
{
2726
public:
2827
AdvertisingDemo();
2928
~AdvertisingDemo() = default;
30-
void runOption(const int index);
29+
void runOption(const std::string& method) override;
3130
};

0 commit comments

Comments
 (0)