Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp-qt] Add option for download progress, add test #19297

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/samples-cpp-qt-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Samples cpp qt client
on:
push:
branches:
- "samples/client/petstore/cpp-qt/**"
- "samples/client/petstore/cpp-qt*/**"
pull_request:
paths:
- "samples/client/petstore/cpp-qt/**"
- "samples/client/petstore/cpp-qt*/**"

env:
GRADLE_VERSION: 6.9
Expand All @@ -16,6 +16,9 @@ jobs:
name: Build cpp qt client
strategy:
matrix:
sample:
- samples/client/petstore/cpp-qt
- samples/client/petstore/cpp-qt-addDownloadProgress
os:
- ubuntu-latest
- macOS-latest
Expand All @@ -29,5 +32,5 @@ jobs:
version: "6.7.1"
target: "desktop"
- name: Build
working-directory: "samples/client/petstore/cpp-qt"
working-directory: ${{ matrix.sample }}
run: cmake . && cmake --build . --verbose
9 changes: 9 additions & 0 deletions bin/configs/cpp-qt-client-addDownloadProgress.yaml
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
1 change: 1 addition & 0 deletions docs/generators/cpp-qt-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|addDownloadProgress|Add support for Qt download progress| |false|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|contentCompression|Enable Compressed Content Encoding for requests and responses| |false|
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenC
// source folder where to write the files
protected String sourceFolder = "client";
@Setter protected boolean optionalProjectFileFlag = true;
@Setter protected boolean addDownloadProgress = false;

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

supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
Expand Down
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.8.0-SNAPSHOT
31 changes: 31 additions & 0 deletions samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt
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)
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");
}

Loading
Loading