Skip to content

Commit eff3e6d

Browse files
authored
[cpp-qt] Add option for download progress, add test (#19297)
* add option for download progress, add test * add cmake file * remove test * update
1 parent ffd03b7 commit eff3e6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+9576
-3
lines changed

.github/workflows/samples-cpp-qt-client.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Samples cpp qt client
33
on:
44
push:
55
branches:
6-
- "samples/client/petstore/cpp-qt/**"
6+
- "samples/client/petstore/cpp-qt*/**"
77
pull_request:
88
paths:
9-
- "samples/client/petstore/cpp-qt/**"
9+
- "samples/client/petstore/cpp-qt*/**"
1010

1111
env:
1212
GRADLE_VERSION: 6.9
@@ -16,6 +16,9 @@ jobs:
1616
name: Build cpp qt client
1717
strategy:
1818
matrix:
19+
sample:
20+
- samples/client/petstore/cpp-qt
21+
- samples/client/petstore/cpp-qt-addDownloadProgress
1922
os:
2023
- ubuntu-latest
2124
- macOS-latest
@@ -29,5 +32,5 @@ jobs:
2932
version: "6.7.1"
3033
target: "desktop"
3134
- name: Build
32-
working-directory: "samples/client/petstore/cpp-qt"
35+
working-directory: ${{ matrix.sample }}
3336
run: cmake . && cmake --build . --verbose
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: cpp-qt-client
2+
outputDir: samples/client/petstore/cpp-qt-addDownloadProgress
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/cpp-qt-client
5+
additionalProperties:
6+
packageName: CppQtPetstoreClient
7+
cppNamespace: test_namespace
8+
modelNamePrefix: PFX
9+
addDownloadProgress: true

docs/generators/cpp-qt-client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1818

1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
21+
|addDownloadProgress|Add support for Qt download progress| |false|
2122
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2223
|contentCompression|Enable Compressed Content Encoding for requests and responses| |false|
2324
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenC
4040
// source folder where to write the files
4141
protected String sourceFolder = "client";
4242
@Setter protected boolean optionalProjectFileFlag = true;
43+
@Setter protected boolean addDownloadProgress = false;
4344

4445
public CppQtClientCodegen() {
4546
super();
@@ -98,6 +99,7 @@ public CppQtClientCodegen() {
9899
// CLI options
99100
addOption(CodegenConstants.PACKAGE_NAME, "C++ package (library) name.", DEFAULT_PACKAGE_NAME);
100101
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
102+
addSwitch("addDownloadProgress", "Add support for Qt download progress", this.addDownloadProgress);
101103

102104
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
103105
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
README.md
2+
client/CMakeLists.txt
3+
client/Config.cmake.in
4+
client/PFXApiResponse.cpp
5+
client/PFXApiResponse.h
6+
client/PFXCategory.cpp
7+
client/PFXCategory.h
8+
client/PFXEnum.h
9+
client/PFXHelpers.cpp
10+
client/PFXHelpers.h
11+
client/PFXHttpFileElement.cpp
12+
client/PFXHttpFileElement.h
13+
client/PFXHttpRequest.cpp
14+
client/PFXHttpRequest.h
15+
client/PFXOauth.cpp
16+
client/PFXOauth.h
17+
client/PFXObject.h
18+
client/PFXOrder.cpp
19+
client/PFXOrder.h
20+
client/PFXPet.cpp
21+
client/PFXPet.h
22+
client/PFXPetApi.cpp
23+
client/PFXPetApi.h
24+
client/PFXPrimitivesApi.cpp
25+
client/PFXPrimitivesApi.h
26+
client/PFXServerConfiguration.h
27+
client/PFXServerVariable.h
28+
client/PFXStoreApi.cpp
29+
client/PFXStoreApi.h
30+
client/PFXTag.cpp
31+
client/PFXTag.h
32+
client/PFXTestAnyType.cpp
33+
client/PFXTestAnyType.h
34+
client/PFXUser.cpp
35+
client/PFXUser.h
36+
client/PFXUserApi.cpp
37+
client/PFXUserApi.h
38+
client/PFXclient.pri
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.8.0-SNAPSHOT
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
3+
project(cpp-qt-petstore)
4+
set(CMAKE_VERBOSE_MAKEFILE ON)
5+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
6+
set(CMAKE_AUTOMOC ON)
7+
8+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui Test)
9+
10+
if(MSVC)
11+
add_compile_options(/W4 /WX)
12+
else()
13+
add_compile_options(-Wall -Wextra -Werror)
14+
endif()
15+
16+
add_subdirectory(client)
17+
18+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)
19+
20+
add_executable(cpp-qt-petstore
21+
PetStore/main.cpp
22+
PetStore/PetApiTests.cpp
23+
PetStore/StoreApiTests.cpp
24+
PetStore/UserApiTests.cpp
25+
)
26+
27+
target_link_libraries(cpp-qt-petstore PRIVATE CppQtPetstoreClient Qt${QT_VERSION_MAJOR}::Test)
28+
29+
enable_testing()
30+
31+
add_test(NAME cpp-qt-petstore-test COMMAND cpp-qt-petstore)
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#include "PetApiTests.h"
2+
3+
#include <QTest>
4+
#include <QTimer>
5+
6+
PFXPet PetApiTests::createRandomPet() {
7+
PFXPet pet;
8+
qint64 id = QDateTime::currentMSecsSinceEpoch();
9+
pet.setName("monster");
10+
pet.setId(id);
11+
pet.setStatus("freaky");
12+
return pet;
13+
}
14+
15+
void PetApiTests::findPetsByStatusTest() {
16+
PFXPetApi api;
17+
QEventLoop loop;
18+
bool petFound = false;
19+
20+
connect(&api, &PFXPetApi::findPetsByStatusSignal, [&](QList<PFXPet> pets) {
21+
petFound = true;
22+
foreach (PFXPet pet, pets) {
23+
QVERIFY(pet.getStatus().startsWith("available") || pet.getStatus().startsWith("sold"));
24+
}
25+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
26+
});
27+
connect(&api, &PFXPetApi::findPetsByStatusSignalError, [&](QList<PFXPet>, QNetworkReply::NetworkError, const QString &error_str) {
28+
qDebug() << "Error happened while issuing request : " << error_str;
29+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
30+
});
31+
32+
api.findPetsByStatus({"available", "sold"});
33+
34+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
35+
loop.exec();
36+
QVERIFY2(petFound, "didn't finish within timeout");
37+
}
38+
39+
void PetApiTests::createAndGetPetTest() {
40+
PFXPetApi api;
41+
api.setApiKey("api_key","special-key");
42+
QEventLoop loop;
43+
bool petCreated = false;
44+
45+
connect(&api, &PFXPetApi::addPetSignal, [&]() {
46+
// pet created
47+
petCreated = true;
48+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
49+
});
50+
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) {
51+
qDebug() << "Error happened while issuing request : " << error_str;
52+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
53+
});
54+
55+
56+
PFXPet pet = createRandomPet();
57+
qint64 id = pet.getId();
58+
59+
api.addPet(pet);
60+
QTimer::singleShot(14000, &loop, &QEventLoop::quit);
61+
loop.exec();
62+
QVERIFY2(petCreated, "didn't finish within timeout");
63+
64+
bool petFetched = false;
65+
66+
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) {
67+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
68+
QVERIFY(pet.getId() > 0);
69+
// QVERIFY(pet.getStatus().compare("freaky") == 0);
70+
petFetched = true;
71+
});
72+
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) {
73+
qDebug() << "Error happened while issuing request : " << error_str;
74+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
75+
});
76+
api.getPetById(id);
77+
QTimer::singleShot(14000, &loop, &QEventLoop::quit);
78+
loop.exec();
79+
QVERIFY2(petFetched, "didn't finish within timeout");
80+
}
81+
82+
void PetApiTests::updatePetTest() {
83+
PFXPetApi api;
84+
85+
PFXPet pet = createRandomPet();
86+
PFXPet petToCheck;
87+
qint64 id = pet.getId();
88+
QEventLoop loop;
89+
bool petAdded = false;
90+
91+
connect(&api, &PFXPetApi::addPetSignal, [&]() {
92+
petAdded = true;
93+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
94+
});
95+
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) {
96+
qDebug() << "Error happened while issuing request : " << error_str;
97+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
98+
});
99+
// create pet
100+
api.addPet(pet);
101+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
102+
loop.exec();
103+
QVERIFY2(petAdded, "didn't finish within timeout");
104+
105+
// fetch it
106+
107+
bool petFetched = false;
108+
connect(&api, &PFXPetApi::getPetByIdSignal, this, [&](PFXPet pet) {
109+
petFetched = true;
110+
petToCheck = pet;
111+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
112+
});
113+
connect(&api, &PFXPetApi::getPetByIdSignalError, this, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) {
114+
qDebug() << "Error happened while issuing request : " << error_str;
115+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
116+
});
117+
// create pet
118+
api.getPetById(id);
119+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
120+
loop.exec();
121+
QVERIFY2(petFetched, "didn't finish within timeout");
122+
123+
// update it
124+
bool petUpdated = false;
125+
connect(&api, &PFXPetApi::updatePetSignal, [&]() {
126+
petUpdated = true;
127+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
128+
});
129+
connect(&api, &PFXPetApi::updatePetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) {
130+
qDebug() << "Error happened while issuing request : " << error_str;
131+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
132+
});
133+
134+
// update pet
135+
petToCheck.setStatus(QString("scary"));
136+
api.updatePet(petToCheck);
137+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
138+
loop.exec();
139+
QVERIFY2(petUpdated, "didn't finish within timeout");
140+
141+
// check it
142+
bool petFetched2 = false;
143+
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) {
144+
petFetched2 = true;
145+
QVERIFY(pet.getId() == petToCheck.getId());
146+
QVERIFY(pet.getStatus().compare(petToCheck.getStatus()) == 0);
147+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
148+
});
149+
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) {
150+
qDebug() << "Error happened while issuing request : " << error_str;
151+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
152+
});
153+
api.getPetById(id);
154+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
155+
loop.exec();
156+
QVERIFY2(petFetched2, "didn't finish within timeout");
157+
}
158+
159+
void PetApiTests::updatePetWithFormTest() {
160+
PFXPetApi api;
161+
162+
PFXPet pet = createRandomPet();
163+
PFXPet petToCheck;
164+
qint64 id = pet.getId();
165+
QEventLoop loop;
166+
167+
// create pet
168+
bool petAdded = false;
169+
connect(&api, &PFXPetApi::addPetSignal, [&]() {
170+
petAdded = true;
171+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
172+
});
173+
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) {
174+
qDebug() << "Error happened while issuing request : " << error_str;
175+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
176+
});
177+
178+
api.addPet(pet);
179+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
180+
loop.exec();
181+
QVERIFY2(petAdded, "didn't finish within timeout");
182+
183+
// fetch it
184+
bool petFetched = false;
185+
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) {
186+
petFetched = true;
187+
petToCheck = pet;
188+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
189+
});
190+
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) {
191+
qDebug() << "Error happened while issuing request : " << error_str;
192+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
193+
});
194+
195+
api.getPetById(id);
196+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
197+
loop.exec();
198+
QVERIFY2(petFetched, "didn't finish within timeout");
199+
200+
// update it
201+
bool petUpdated = false;
202+
connect(&api, &PFXPetApi::updatePetWithFormSignal, [&]() {
203+
petUpdated = true;
204+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
205+
});
206+
connect(&api, &PFXPetApi::updatePetWithFormSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) {
207+
qDebug() << "Error happened while issuing request : " << error_str;
208+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
209+
});
210+
211+
QString name("gorilla");
212+
api.updatePetWithForm(id, name);
213+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
214+
loop.exec();
215+
QVERIFY2(petUpdated, "didn't finish within timeout");
216+
217+
// fetch it
218+
bool petUpdated2 = false;
219+
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) {
220+
Q_UNUSED(pet);
221+
petUpdated2 = true;
222+
// QVERIFY(pet.getName().compare(QString("gorilla")) == 0);
223+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
224+
});
225+
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) {
226+
qDebug() << "Error happened while issuing request : " << error_str;
227+
QTimer::singleShot(0, &loop, &QEventLoop::quit);
228+
});
229+
230+
api.getPetById(id);
231+
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
232+
loop.exec();
233+
QVERIFY2(petUpdated2, "didn't finish within timeout");
234+
}
235+

0 commit comments

Comments
 (0)