-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cpp-qt] Add option for download progress, add test (#19297)
* add option for download progress, add test * add cmake file * remove test * update
- Loading branch information
Showing
56 changed files
with
9,576 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
generatorName: cpp-qt-client | ||
outputDir: samples/client/petstore/cpp-qt-addDownloadProgress | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/cpp-qt-client | ||
additionalProperties: | ||
packageName: CppQtPetstoreClient | ||
cppNamespace: test_namespace | ||
modelNamePrefix: PFX | ||
addDownloadProgress: true |
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
23 changes: 23 additions & 0 deletions
23
samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator-ignore
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 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
38 changes: 38 additions & 0 deletions
38
samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/FILES
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,38 @@ | ||
README.md | ||
client/CMakeLists.txt | ||
client/Config.cmake.in | ||
client/PFXApiResponse.cpp | ||
client/PFXApiResponse.h | ||
client/PFXCategory.cpp | ||
client/PFXCategory.h | ||
client/PFXEnum.h | ||
client/PFXHelpers.cpp | ||
client/PFXHelpers.h | ||
client/PFXHttpFileElement.cpp | ||
client/PFXHttpFileElement.h | ||
client/PFXHttpRequest.cpp | ||
client/PFXHttpRequest.h | ||
client/PFXOauth.cpp | ||
client/PFXOauth.h | ||
client/PFXObject.h | ||
client/PFXOrder.cpp | ||
client/PFXOrder.h | ||
client/PFXPet.cpp | ||
client/PFXPet.h | ||
client/PFXPetApi.cpp | ||
client/PFXPetApi.h | ||
client/PFXPrimitivesApi.cpp | ||
client/PFXPrimitivesApi.h | ||
client/PFXServerConfiguration.h | ||
client/PFXServerVariable.h | ||
client/PFXStoreApi.cpp | ||
client/PFXStoreApi.h | ||
client/PFXTag.cpp | ||
client/PFXTag.h | ||
client/PFXTestAnyType.cpp | ||
client/PFXTestAnyType.h | ||
client/PFXUser.cpp | ||
client/PFXUser.h | ||
client/PFXUserApi.cpp | ||
client/PFXUserApi.h | ||
client/PFXclient.pri |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/VERSION
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 @@ | ||
7.8.0-SNAPSHOT |
31 changes: 31 additions & 0 deletions
31
samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt
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,31 @@ | ||
cmake_minimum_required(VERSION 3.2) | ||
|
||
project(cpp-qt-petstore) | ||
set(CMAKE_VERBOSE_MAKEFILE ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui Test) | ||
|
||
if(MSVC) | ||
add_compile_options(/W4 /WX) | ||
else() | ||
add_compile_options(-Wall -Wextra -Werror) | ||
endif() | ||
|
||
add_subdirectory(client) | ||
|
||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test) | ||
|
||
add_executable(cpp-qt-petstore | ||
PetStore/main.cpp | ||
PetStore/PetApiTests.cpp | ||
PetStore/StoreApiTests.cpp | ||
PetStore/UserApiTests.cpp | ||
) | ||
|
||
target_link_libraries(cpp-qt-petstore PRIVATE CppQtPetstoreClient Qt${QT_VERSION_MAJOR}::Test) | ||
|
||
enable_testing() | ||
|
||
add_test(NAME cpp-qt-petstore-test COMMAND cpp-qt-petstore) |
235 changes: 235 additions & 0 deletions
235
samples/client/petstore/cpp-qt-addDownloadProgress/PetStore/PetApiTests.cpp
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,235 @@ | ||
#include "PetApiTests.h" | ||
|
||
#include <QTest> | ||
#include <QTimer> | ||
|
||
PFXPet PetApiTests::createRandomPet() { | ||
PFXPet pet; | ||
qint64 id = QDateTime::currentMSecsSinceEpoch(); | ||
pet.setName("monster"); | ||
pet.setId(id); | ||
pet.setStatus("freaky"); | ||
return pet; | ||
} | ||
|
||
void PetApiTests::findPetsByStatusTest() { | ||
PFXPetApi api; | ||
QEventLoop loop; | ||
bool petFound = false; | ||
|
||
connect(&api, &PFXPetApi::findPetsByStatusSignal, [&](QList<PFXPet> pets) { | ||
petFound = true; | ||
foreach (PFXPet pet, pets) { | ||
QVERIFY(pet.getStatus().startsWith("available") || pet.getStatus().startsWith("sold")); | ||
} | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::findPetsByStatusSignalError, [&](QList<PFXPet>, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
api.findPetsByStatus({"available", "sold"}); | ||
|
||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petFound, "didn't finish within timeout"); | ||
} | ||
|
||
void PetApiTests::createAndGetPetTest() { | ||
PFXPetApi api; | ||
api.setApiKey("api_key","special-key"); | ||
QEventLoop loop; | ||
bool petCreated = false; | ||
|
||
connect(&api, &PFXPetApi::addPetSignal, [&]() { | ||
// pet created | ||
petCreated = true; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
|
||
PFXPet pet = createRandomPet(); | ||
qint64 id = pet.getId(); | ||
|
||
api.addPet(pet); | ||
QTimer::singleShot(14000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petCreated, "didn't finish within timeout"); | ||
|
||
bool petFetched = false; | ||
|
||
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) { | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
QVERIFY(pet.getId() > 0); | ||
// QVERIFY(pet.getStatus().compare("freaky") == 0); | ||
petFetched = true; | ||
}); | ||
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
api.getPetById(id); | ||
QTimer::singleShot(14000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petFetched, "didn't finish within timeout"); | ||
} | ||
|
||
void PetApiTests::updatePetTest() { | ||
PFXPetApi api; | ||
|
||
PFXPet pet = createRandomPet(); | ||
PFXPet petToCheck; | ||
qint64 id = pet.getId(); | ||
QEventLoop loop; | ||
bool petAdded = false; | ||
|
||
connect(&api, &PFXPetApi::addPetSignal, [&]() { | ||
petAdded = true; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
// create pet | ||
api.addPet(pet); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petAdded, "didn't finish within timeout"); | ||
|
||
// fetch it | ||
|
||
bool petFetched = false; | ||
connect(&api, &PFXPetApi::getPetByIdSignal, this, [&](PFXPet pet) { | ||
petFetched = true; | ||
petToCheck = pet; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::getPetByIdSignalError, this, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
// create pet | ||
api.getPetById(id); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petFetched, "didn't finish within timeout"); | ||
|
||
// update it | ||
bool petUpdated = false; | ||
connect(&api, &PFXPetApi::updatePetSignal, [&]() { | ||
petUpdated = true; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::updatePetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
// update pet | ||
petToCheck.setStatus(QString("scary")); | ||
api.updatePet(petToCheck); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petUpdated, "didn't finish within timeout"); | ||
|
||
// check it | ||
bool petFetched2 = false; | ||
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) { | ||
petFetched2 = true; | ||
QVERIFY(pet.getId() == petToCheck.getId()); | ||
QVERIFY(pet.getStatus().compare(petToCheck.getStatus()) == 0); | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
api.getPetById(id); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petFetched2, "didn't finish within timeout"); | ||
} | ||
|
||
void PetApiTests::updatePetWithFormTest() { | ||
PFXPetApi api; | ||
|
||
PFXPet pet = createRandomPet(); | ||
PFXPet petToCheck; | ||
qint64 id = pet.getId(); | ||
QEventLoop loop; | ||
|
||
// create pet | ||
bool petAdded = false; | ||
connect(&api, &PFXPetApi::addPetSignal, [&]() { | ||
petAdded = true; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::addPetSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
api.addPet(pet); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petAdded, "didn't finish within timeout"); | ||
|
||
// fetch it | ||
bool petFetched = false; | ||
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) { | ||
petFetched = true; | ||
petToCheck = pet; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
api.getPetById(id); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petFetched, "didn't finish within timeout"); | ||
|
||
// update it | ||
bool petUpdated = false; | ||
connect(&api, &PFXPetApi::updatePetWithFormSignal, [&]() { | ||
petUpdated = true; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::updatePetWithFormSignalError, [&](QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
QString name("gorilla"); | ||
api.updatePetWithForm(id, name); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petUpdated, "didn't finish within timeout"); | ||
|
||
// fetch it | ||
bool petUpdated2 = false; | ||
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) { | ||
Q_UNUSED(pet); | ||
petUpdated2 = true; | ||
// QVERIFY(pet.getName().compare(QString("gorilla")) == 0); | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
connect(&api, &PFXPetApi::getPetByIdSignalError, [&](PFXPet, QNetworkReply::NetworkError, const QString &error_str) { | ||
qDebug() << "Error happened while issuing request : " << error_str; | ||
QTimer::singleShot(0, &loop, &QEventLoop::quit); | ||
}); | ||
|
||
api.getPetById(id); | ||
QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
QVERIFY2(petUpdated2, "didn't finish within timeout"); | ||
} | ||
|
Oops, something went wrong.