-
Notifications
You must be signed in to change notification settings - Fork 1
test(coverage): quick wins for CLIPipeline/mainwindow/MaterialEditorQML #266
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <QSignalSpy> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <QThread> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <QDir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <QFile> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <QTemporaryDir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "MaterialEditorQML.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "Manager.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <OgreException.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -138,6 +140,66 @@ TEST_F(MaterialEditorQMLTest, FileSystem_ListDirectory) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_EQ(empty.size(), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, FileSystem_ListDirectoryFiltersOnlyImagesAndDirectories) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QTemporaryDir tempDir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(tempDir.isValid()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString subdirPath = tempDir.filePath("textures"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(QDir().mkpath(subdirPath)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QFile imageFile(tempDir.filePath("albedo.png")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(imageFile.open(QIODevice::WriteOnly)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imageFile.write("png"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imageFile.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QFile textFile(tempDir.filePath("notes.txt")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(textFile.open(QIODevice::WriteOnly)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textFile.write("txt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textFile.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QVariantList entries = editor->listDirectory(tempDir.path()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_GE(entries.size(), 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool foundDir = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool foundImage = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool foundText = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const QVariant& v : entries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QVariantMap item = v.toMap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString name = item.value("name").toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString type = item.value("type").toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name == "textures" && type == "dir") foundDir = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name == "albedo.png" && type == "file") foundImage = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name == "notes.txt") foundText = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(foundDir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(foundImage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_FALSE(foundText); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, FileSystem_GetFileSizeStringCoversKbAndMbBranches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QTemporaryDir tempDir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(tempDir.isValid()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString kbPath = tempDir.filePath("kb.bin"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QFile kbFile(kbPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(kbFile.open(QIODevice::WriteOnly)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kbFile.write(QByteArray(2048, 'k')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kbFile.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString mbPath = tempDir.filePath("mb.bin"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QFile mbFile(mbPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_TRUE(mbFile.open(QIODevice::WriteOnly)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mbFile.write(QByteArray(2 * 1024 * 1024, 'm')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mbFile.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString kbSize = editor->getFileSizeString(kbPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString mbSize = editor->getFileSizeString(mbPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(kbSize.contains("KB")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(mbSize.contains("MB")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // =========================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Basic fixture tests -- enum name getters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // =========================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1877,6 +1939,65 @@ TEST_F(MaterialEditorQMLTest, LLMProperties_InitialState) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Q_UNUSED(model); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, GenerateMaterialFromPrompt_EmptyPromptEmitsError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::aiGenerationError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editor->generateMaterialFromPrompt(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(errorSpy.count(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QList<QVariant> args = errorSpy.takeFirst(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(args.size(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_EQ(args.at(0).toString(), "Please enter a prompt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, GenerateMaterialFromPrompt_NoModelLoadedEmitsError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (editor->llmModelLoaded()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GTEST_SKIP() << "LLM model is already loaded in this environment"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::aiGenerationError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editor->generateMaterialFromPrompt("polished metal with scratches"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_GE(errorSpy.count(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QList<QVariant> args = errorSpy.takeFirst(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(args.size(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(args.at(0).toString().contains("No AI model loaded")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, GenerateTextureFromPrompt_EmptyPromptEmitsError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::sdGenerationError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editor->generateTextureFromPrompt("", 512, 512); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(errorSpy.count(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QList<QVariant> args = errorSpy.takeFirst(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(args.size(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_EQ(args.at(0).toString(), "Please enter a texture prompt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, GenerateTextureFromPrompt_ReportsUnavailableBackendOrModel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::sdGenerationError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editor->generateTextureFromPrompt("brushed steel", 512, 512); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_GE(errorSpy.count(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QList<QVariant> args = errorSpy.takeFirst(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASSERT_EQ(args.size(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QString message = args.at(0).toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (editor->stableDiffusionEnabled()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(message.contains("No SD model loaded") || message.contains("AI Settings")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_TRUE(message.contains("Stable Diffusion support is not enabled")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1979
to
+1994
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the SD unavailable-path assertion deterministic across environments. This test hard-requires an error signal, but in environments where SD is fully available/configured, Proposed test hardening TEST_F(MaterialEditorQMLTest, GenerateTextureFromPrompt_ReportsUnavailableBackendOrModel) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::sdGenerationError);
editor->generateTextureFromPrompt("brushed steel", 512, 512);
- ASSERT_GE(errorSpy.count(), 1);
+ if (errorSpy.count() == 0 && !errorSpy.wait(300)) {
+ GTEST_SKIP() << "Stable Diffusion backend appears available/configured; unavailable-path assertion not applicable";
+ }
+ ASSERT_GE(errorSpy.count(), 1);
const QList<QVariant> args = errorSpy.takeFirst();
ASSERT_EQ(args.size(), 1);
const QString message = args.at(0).toString();
if (editor->stableDiffusionEnabled()) {
EXPECT_TRUE(message.contains("No SD model loaded") || message.contains("AI Settings"));
} else {
EXPECT_TRUE(message.contains("Stable Diffusion support is not enabled"));
}
}As per coding guidelines: "Features depending on optional components (e.g., local LLM / llama.cpp) may not be available in the test environment — guard with 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TEST_F(MaterialEditorQMLTest, StopGenerationMethodsWithoutActiveJobsDoNotCrash) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_NO_THROW(editor->stopAIGeneration()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_NO_THROW(editor->stopTextureGeneration()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // =========================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Additional coverage tests (MaterialEditorQMLTest fixture) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // =========================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generateTextureFromPrompt("brushed steel", ...)only emitssdGenerationErrorsynchronously when SD is disabled or no SD model is loaded; whenENABLE_STABLE_DIFFUSIONis on and a model has already been auto-loaded, the call takes the generation path and this assertion fails immediately even though nothing is wrong. This makes the test environment-dependent/flaky (similar to the LLM test right above, which already skips when a model is loaded), so the check should be conditioned onsdModelLoaded()or otherwise handle the loaded-model path explicitly.Useful? React with 👍 / 👎.