-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterialEditorQML_test.cpp
More file actions
2415 lines (1991 loc) · 85.1 KB
/
MaterialEditorQML_test.cpp
File metadata and controls
2415 lines (1991 loc) · 85.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <gtest/gtest.h>
#include <memory>
#include <QApplication>
#include <QCoreApplication>
#include <QSignalSpy>
#include <QThread>
#include <QDir>
#include "MaterialEditorQML.h"
#include "Manager.h"
#include <OgreException.h>
#include "TestHelpers.h"
// Ensure a QApplication exists for the process lifetime.
// gtest_main does not create one, so we lazily create it here.
static QApplication* ensureQApplication()
{
QApplication* app = qobject_cast<QApplication*>(QCoreApplication::instance());
if (!app) {
static int argc = 1;
static char appName[] = "MaterialEditorQML_test";
static char* argv[] = {appName, nullptr};
app = new QApplication(argc, argv); // NOSONAR - intentional: QApplication must outlive all tests
}
return app;
}
// ---------------------------------------------------------------------------
// Basic fixture (no Ogre needed)
// ---------------------------------------------------------------------------
class MaterialEditorQMLTest : public ::testing::Test {
protected:
void SetUp() override {
// Ensure no Ogre state leaks from prior test suites so that
// isOgreAvailable() reliably returns false for these tests.
Manager::kill();
QThread::msleep(50);
app = ensureQApplication();
ASSERT_NE(app, nullptr);
editor = std::make_unique<MaterialEditorQML>();
}
void TearDown() override {
editor.reset();
}
QApplication* app = nullptr;
std::unique_ptr<MaterialEditorQML> editor;
};
// ---------------------------------------------------------------------------
// Ogre fixture
// ---------------------------------------------------------------------------
class MaterialEditorQMLWithOgreTest : public ::testing::Test {
protected:
void SetUp() override {
Manager::kill();
QThread::msleep(50);
app = ensureQApplication();
ASSERT_NE(app, nullptr);
if (!tryInitOgre()) {
GTEST_SKIP() << "Skipping: Ogre initialization failed";
}
createStandardOgreMaterials();
editor = std::make_unique<MaterialEditorQML>();
}
void TearDown() override {
editor.reset();
if (app) {
app->processEvents();
}
}
QApplication* app = nullptr;
std::unique_ptr<MaterialEditorQML> editor;
};
// ===========================================================================
// Basic fixture tests -- file system helpers
// ===========================================================================
TEST_F(MaterialEditorQMLTest, FileSystem_IsDirectory) {
// A known directory should return true
EXPECT_TRUE(editor->isDirectory("/tmp"));
// A non-existent or file path should return false
EXPECT_FALSE(editor->isDirectory("/tmp/nonexistent_path_xyz_12345"));
}
TEST_F(MaterialEditorQMLTest, FileSystem_GetParentDirectory) {
QString parent = editor->getParentDirectory("/tmp/somefile.txt");
EXPECT_EQ(parent, "/tmp");
QString parent2 = editor->getParentDirectory("/usr/local/bin");
EXPECT_EQ(parent2, "/usr/local");
}
TEST_F(MaterialEditorQMLTest, FileSystem_GetFileName) {
QString name = editor->getFileName("/some/path/texture.png");
EXPECT_EQ(name, "texture.png");
QString name2 = editor->getFileName("/another/directory/file.material");
EXPECT_EQ(name2, "file.material");
}
TEST_F(MaterialEditorQMLTest, FileSystem_PathExists) {
EXPECT_TRUE(editor->pathExists("/tmp"));
EXPECT_FALSE(editor->pathExists("/nonexistent_path_xyz_99999"));
}
TEST_F(MaterialEditorQMLTest, FileSystem_GetFileSize) {
// /tmp always exists as a directory; its size is platform-dependent
// but should be non-negative
qint64 size = editor->getFileSize("/tmp");
EXPECT_GE(size, 0);
}
TEST_F(MaterialEditorQMLTest, FileSystem_GetFileSizeString) {
// The format should contain B, KB, or MB
QString sizeStr = editor->getFileSizeString("/tmp");
EXPECT_TRUE(sizeStr.contains("B") || sizeStr.contains("KB") || sizeStr.contains("MB"));
}
TEST_F(MaterialEditorQMLTest, FileSystem_ListDirectory) {
// /tmp should have some entries (or at least be a valid call)
QVariantList entries = editor->listDirectory("/tmp");
// We simply verify the call succeeds. /tmp might have image files or not,
// but the result type should be a list.
// listDirectory filters for image files + dirs, so we just check it doesn't crash.
EXPECT_GE(entries.size(), 0);
// Non-existent directory should return empty list
QVariantList empty = editor->listDirectory("/nonexistent_path_xyz_99999");
EXPECT_EQ(empty.size(), 0);
}
// ===========================================================================
// Basic fixture tests -- enum name getters
// ===========================================================================
TEST_F(MaterialEditorQMLTest, GetPolygonModeNames) {
QStringList names = editor->getPolygonModeNames();
EXPECT_EQ(names.size(), 3);
EXPECT_EQ(names[0], "Points");
EXPECT_EQ(names[1], "Wireframe");
EXPECT_EQ(names[2], "Solid");
}
TEST_F(MaterialEditorQMLTest, GetBlendFactorNames) {
QStringList names = editor->getBlendFactorNames();
EXPECT_FALSE(names.isEmpty());
// Should contain known entries
EXPECT_TRUE(names.contains("One"));
EXPECT_TRUE(names.contains("Zero"));
}
TEST_F(MaterialEditorQMLTest, GetShadingModeNames) {
QStringList names = editor->getShadingModeNames();
EXPECT_EQ(names.size(), 3);
EXPECT_EQ(names[0], "Flat");
EXPECT_EQ(names[1], "Gouraud");
EXPECT_EQ(names[2], "Phong");
}
TEST_F(MaterialEditorQMLTest, GetCullModeNames) {
QStringList names = editor->getCullModeNames();
EXPECT_EQ(names.size(), 3);
EXPECT_TRUE(names.contains("None"));
EXPECT_TRUE(names.contains("Clockwise"));
EXPECT_TRUE(names.contains("Counter-Clockwise"));
}
TEST_F(MaterialEditorQMLTest, GetDepthFunctionNames) {
QStringList names = editor->getDepthFunctionNames();
EXPECT_EQ(names.size(), 8);
EXPECT_TRUE(names.contains("Less"));
EXPECT_TRUE(names.contains("Greater"));
}
TEST_F(MaterialEditorQMLTest, GetAlphaRejectionFunctionNames) {
QStringList names = editor->getAlphaRejectionFunctionNames();
EXPECT_EQ(names.size(), 8);
EXPECT_TRUE(names.contains("Always Pass"));
}
TEST_F(MaterialEditorQMLTest, GetSceneBlendOperationNames) {
QStringList names = editor->getSceneBlendOperationNames();
EXPECT_EQ(names.size(), 5);
EXPECT_TRUE(names.contains("Add"));
EXPECT_TRUE(names.contains("Max"));
}
TEST_F(MaterialEditorQMLTest, GetFogModeNames) {
QStringList names = editor->getFogModeNames();
EXPECT_EQ(names.size(), 4);
EXPECT_TRUE(names.contains("None"));
EXPECT_TRUE(names.contains("Linear"));
}
TEST_F(MaterialEditorQMLTest, GetTextureAddressModeNames) {
QStringList names = editor->getTextureAddressModeNames();
EXPECT_EQ(names.size(), 4);
EXPECT_TRUE(names.contains("Wrap"));
EXPECT_TRUE(names.contains("Border"));
}
TEST_F(MaterialEditorQMLTest, GetTextureFilteringNames) {
QStringList names = editor->getTextureFilteringNames();
EXPECT_EQ(names.size(), 4);
EXPECT_TRUE(names.contains("Bilinear"));
EXPECT_TRUE(names.contains("Anisotropic"));
}
TEST_F(MaterialEditorQMLTest, GetEnvironmentMappingNames) {
QStringList names = editor->getEnvironmentMappingNames();
EXPECT_EQ(names.size(), 2);
EXPECT_TRUE(names.contains("None"));
EXPECT_TRUE(names.contains("Enabled"));
}
// ===========================================================================
// Basic fixture tests -- createNewMaterial (no Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLTest, CreateNewMaterial_DefaultName) {
QSignalSpy nameSpy(editor.get(), &MaterialEditorQML::materialNameChanged);
QSignalSpy textSpy(editor.get(), &MaterialEditorQML::materialTextChanged);
editor->createNewMaterial();
EXPECT_EQ(editor->materialName(), "new_material");
EXPECT_TRUE(editor->materialText().contains("material new_material"));
EXPECT_GE(nameSpy.count(), 1);
EXPECT_GE(textSpy.count(), 1);
}
TEST_F(MaterialEditorQMLTest, CreateNewMaterial_CustomName) {
editor->createNewMaterial("MyTestMat");
EXPECT_EQ(editor->materialName(), "MyTestMat");
EXPECT_TRUE(editor->materialText().contains("material MyTestMat"));
}
// ===========================================================================
// Basic fixture tests -- validate material script (no Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLTest, ValidateMaterialScript_Valid) {
QString validScript =
"material TestMaterial\n"
"{\n"
"\ttechnique\n"
"\t{\n"
"\t\tpass\n"
"\t\t{\n"
"\t\t}\n"
"\t}\n"
"}";
EXPECT_TRUE(editor->validateMaterialScript(validScript));
}
TEST_F(MaterialEditorQMLTest, ValidateMaterialScript_Empty) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
EXPECT_FALSE(editor->validateMaterialScript(""));
EXPECT_GE(errorSpy.count(), 1);
}
TEST_F(MaterialEditorQMLTest, ValidateMaterialScript_MissingTechnique) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
QString script =
"material TestMaterial\n"
"{\n"
"}";
EXPECT_FALSE(editor->validateMaterialScript(script));
EXPECT_GE(errorSpy.count(), 1);
}
TEST_F(MaterialEditorQMLTest, ValidateMaterialScript_MismatchedBraces) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
QString script =
"material TestMaterial\n"
"{\n"
"\ttechnique\n"
"\t{\n"
"\t\tpass\n"
"\t\t{\n"
"\t}\n"
"}";
EXPECT_FALSE(editor->validateMaterialScript(script));
EXPECT_GE(errorSpy.count(), 1);
}
// ===========================================================================
// Basic fixture tests -- undo/redo (no Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLTest, UndoRedo_InitialState) {
EXPECT_FALSE(editor->canUndo());
EXPECT_FALSE(editor->canRedo());
}
TEST_F(MaterialEditorQMLTest, UndoRedo_AfterChanges) {
// Set initial text
editor->setMaterialText("first text");
// After first set, undo stack should be empty (no previous text)
EXPECT_FALSE(editor->canUndo());
// Change text -- now "first text" goes to undo stack
editor->setMaterialText("second text");
EXPECT_TRUE(editor->canUndo());
EXPECT_FALSE(editor->canRedo());
// Undo should restore "first text"
editor->undo();
EXPECT_EQ(editor->materialText(), "first text");
EXPECT_FALSE(editor->canUndo());
EXPECT_TRUE(editor->canRedo());
// Redo should restore "second text"
editor->redo();
EXPECT_EQ(editor->materialText(), "second text");
EXPECT_TRUE(editor->canUndo());
EXPECT_FALSE(editor->canRedo());
}
TEST_F(MaterialEditorQMLTest, UndoRedo_ClearHistory) {
editor->setMaterialText("first");
editor->setMaterialText("second");
EXPECT_TRUE(editor->canUndo());
editor->clearUndoHistory();
EXPECT_FALSE(editor->canUndo());
EXPECT_FALSE(editor->canRedo());
}
// ===========================================================================
// Basic fixture tests -- property setters emit signals (no Ogre pass)
// ===========================================================================
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_Lighting) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::lightingEnabledChanged);
editor->setLightingEnabled(false);
EXPECT_GE(spy.count(), 1);
EXPECT_FALSE(editor->lightingEnabled());
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_DepthWrite) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::depthWriteEnabledChanged);
editor->setDepthWriteEnabled(false);
EXPECT_GE(spy.count(), 1);
EXPECT_FALSE(editor->depthWriteEnabled());
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_AmbientColor) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::ambientColorChanged);
QColor newColor(255, 0, 0);
editor->setAmbientColor(newColor);
EXPECT_GE(spy.count(), 1);
EXPECT_EQ(editor->ambientColor(), newColor);
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_DiffuseColor) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::diffuseColorChanged);
QColor newColor(0, 255, 0);
editor->setDiffuseColor(newColor);
EXPECT_GE(spy.count(), 1);
EXPECT_EQ(editor->diffuseColor(), newColor);
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_Shininess) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::shininessChanged);
editor->setShininess(42.0f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->shininess(), 42.0f);
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_PolygonMode) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::polygonModeChanged);
editor->setPolygonMode(0); // Points
EXPECT_GE(spy.count(), 1);
EXPECT_EQ(editor->polygonMode(), 0);
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_NoSignalOnSameValue) {
// Setting the same default value should not emit a signal
QSignalSpy spy(editor.get(), &MaterialEditorQML::lightingEnabledChanged);
editor->setLightingEnabled(true); // default is true
EXPECT_EQ(spy.count(), 0);
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_FogOverride) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::fogOverrideChanged);
editor->setFogOverride(true);
EXPECT_GE(spy.count(), 1);
EXPECT_TRUE(editor->fogOverride());
}
TEST_F(MaterialEditorQMLTest, PropertySettersAndSignals_PointSize) {
QSignalSpy spy(editor.get(), &MaterialEditorQML::pointSizeChanged);
editor->setPointSize(5.0f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->pointSize(), 5.0f);
}
// ===========================================================================
// Basic fixture tests -- theme colors (constants)
// ===========================================================================
TEST_F(MaterialEditorQMLTest, ThemeColors_AreValid) {
EXPECT_TRUE(editor->backgroundColor().isValid());
EXPECT_TRUE(editor->panelColor().isValid());
EXPECT_TRUE(editor->textColor().isValid());
EXPECT_TRUE(editor->borderColor().isValid());
EXPECT_TRUE(editor->highlightColor().isValid());
EXPECT_TRUE(editor->buttonColor().isValid());
EXPECT_TRUE(editor->buttonTextColor().isValid());
EXPECT_TRUE(editor->accentColor().isValid());
}
// ===========================================================================
// Basic fixture tests -- testConnection
// ===========================================================================
TEST_F(MaterialEditorQMLTest, TestConnection) {
QString result = editor->testConnection();
EXPECT_FALSE(result.isEmpty());
EXPECT_TRUE(result.contains("successfully"));
}
// ===========================================================================
// Ogre fixture tests
// ===========================================================================
TEST_F(MaterialEditorQMLWithOgreTest, CreateNewMaterial) {
QSignalSpy nameSpy(editor.get(), &MaterialEditorQML::materialNameChanged);
editor->createNewMaterial("OgreTestMat");
EXPECT_EQ(editor->materialName(), "OgreTestMat");
EXPECT_TRUE(editor->materialText().contains("material OgreTestMat"));
EXPECT_GE(nameSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, LoadMaterial_BaseWhite) {
QSignalSpy nameSpy(editor.get(), &MaterialEditorQML::materialNameChanged);
editor->loadMaterial("BaseWhite");
EXPECT_EQ(editor->materialName(), "BaseWhite");
EXPECT_GE(nameSpy.count(), 1);
// The material text should contain the material name
EXPECT_TRUE(editor->materialText().contains("BaseWhite"));
// After loading, technique list should be populated
EXPECT_FALSE(editor->techniqueList().isEmpty());
}
TEST_F(MaterialEditorQMLWithOgreTest, LoadMaterial_NonExistent) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
editor->loadMaterial("NonExistentMaterial_XYZ_12345");
EXPECT_GE(errorSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, LoadMaterial_Empty) {
// Loading empty name should create a new material
editor->loadMaterial("");
EXPECT_EQ(editor->materialName(), "new_material");
}
TEST_F(MaterialEditorQMLWithOgreTest, ValidateMaterialScript_ValidWithOgre) {
editor->setMaterialName("TestValidation");
QString validScript =
"material TestValidation\n"
"{\n"
"\ttechnique\n"
"\t{\n"
"\t\tpass\n"
"\t\t{\n"
"\t\t}\n"
"\t}\n"
"}";
EXPECT_TRUE(editor->validateMaterialScript(validScript));
}
TEST_F(MaterialEditorQMLWithOgreTest, ValidateMaterialScript_InvalidWithOgre) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
EXPECT_FALSE(editor->validateMaterialScript("not a valid material script at all"));
EXPECT_GE(errorSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, MaterialList_NonEmpty) {
QStringList materials = editor->getMaterialList();
EXPECT_FALSE(materials.isEmpty());
// Should at least contain BaseWhite and BaseWhiteNoLighting
EXPECT_TRUE(materials.contains("BaseWhite"));
EXPECT_TRUE(materials.contains("BaseWhiteNoLighting"));
}
TEST_F(MaterialEditorQMLWithOgreTest, CreateTechniquePassTextureUnit) {
// Load BaseWhite so we have a valid Ogre material
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->techniqueList().isEmpty());
int originalTechCount = editor->techniqueList().size();
// Create a new technique
editor->createNewTechnique("TestTechnique");
EXPECT_EQ(editor->techniqueList().size(), originalTechCount + 1);
// Select the new technique
editor->setSelectedTechniqueIndex(editor->techniqueList().size() - 1);
// The new technique should have no passes initially
// (createNewTechnique does NOT auto-create a pass)
// Actually, after selecting technique the passList updates
int passCount = editor->passList().size();
// Create a new pass
editor->createNewPass("TestPass");
EXPECT_GT(editor->passList().size(), passCount);
// Select the pass
editor->setSelectedPassIndex(editor->passList().size() - 1);
// Create a texture unit
int texUnitCount = editor->textureUnitList().size();
editor->createNewTextureUnit("TestTexUnit");
EXPECT_GT(editor->textureUnitList().size(), texUnitCount);
}
TEST_F(MaterialEditorQMLWithOgreTest, PropertySettersWithOgrePass) {
// Load a material so we have a valid pass
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->techniqueList().isEmpty());
ASSERT_FALSE(editor->passList().isEmpty());
// Set various properties and verify they take effect
QSignalSpy lightingSpy(editor.get(), &MaterialEditorQML::lightingEnabledChanged);
editor->setLightingEnabled(false);
EXPECT_GE(lightingSpy.count(), 1);
EXPECT_FALSE(editor->lightingEnabled());
QSignalSpy depthWriteSpy(editor.get(), &MaterialEditorQML::depthWriteEnabledChanged);
editor->setDepthWriteEnabled(false);
EXPECT_GE(depthWriteSpy.count(), 1);
QSignalSpy depthCheckSpy(editor.get(), &MaterialEditorQML::depthCheckEnabledChanged);
editor->setDepthCheckEnabled(false);
EXPECT_GE(depthCheckSpy.count(), 1);
QSignalSpy shininessSpy(editor.get(), &MaterialEditorQML::shininessChanged);
editor->setShininess(64.0f);
EXPECT_GE(shininessSpy.count(), 1);
EXPECT_FLOAT_EQ(editor->shininess(), 64.0f);
// Material text should update after property changes
EXPECT_FALSE(editor->materialText().isEmpty());
}
TEST_F(MaterialEditorQMLWithOgreTest, ColorSettersWithOgrePass) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->techniqueList().isEmpty());
ASSERT_FALSE(editor->passList().isEmpty());
QColor red(255, 0, 0);
QColor green(0, 255, 0);
QColor blue(0, 0, 255);
QSignalSpy ambientSpy(editor.get(), &MaterialEditorQML::ambientColorChanged);
editor->setAmbientColor(red);
EXPECT_GE(ambientSpy.count(), 1);
QSignalSpy diffuseSpy(editor.get(), &MaterialEditorQML::diffuseColorChanged);
editor->setDiffuseColor(green);
EXPECT_GE(diffuseSpy.count(), 1);
QSignalSpy specularSpy(editor.get(), &MaterialEditorQML::specularColorChanged);
editor->setSpecularColor(blue);
EXPECT_GE(specularSpy.count(), 1);
QSignalSpy emissiveSpy(editor.get(), &MaterialEditorQML::emissiveColorChanged);
editor->setEmissiveColor(red);
EXPECT_GE(emissiveSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, AdvancedPassProperties) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->techniqueList().isEmpty());
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy shadingSpy(editor.get(), &MaterialEditorQML::shadingModeChanged);
editor->setShadingMode(2); // Phong
EXPECT_GE(shadingSpy.count(), 1);
EXPECT_EQ(editor->shadingMode(), 2);
QSignalSpy cullHwSpy(editor.get(), &MaterialEditorQML::cullHardwareChanged);
editor->setCullHardware(0); // None
EXPECT_GE(cullHwSpy.count(), 1);
QSignalSpy cullSwSpy(editor.get(), &MaterialEditorQML::cullSoftwareChanged);
editor->setCullSoftware(2); // Front
EXPECT_GE(cullSwSpy.count(), 1);
QSignalSpy blendOpSpy(editor.get(), &MaterialEditorQML::sceneBlendOperationChanged);
editor->setSceneBlendOperation(1); // Subtract
EXPECT_GE(blendOpSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, UndoRedo_WithOgreMaterial) {
editor->loadMaterial("BaseWhite");
QString originalText = editor->materialText();
// Change a property which updates material text
editor->setLightingEnabled(false);
QString modifiedText = editor->materialText();
EXPECT_NE(originalText, modifiedText);
// Undo should restore the previous material text
EXPECT_TRUE(editor->canUndo());
editor->undo();
EXPECT_EQ(editor->materialText(), originalText);
// Redo should restore the modified text
EXPECT_TRUE(editor->canRedo());
editor->redo();
EXPECT_EQ(editor->materialText(), modifiedText);
}
TEST_F(MaterialEditorQMLWithOgreTest, SelectedIndices_Update) {
editor->loadMaterial("BaseWhite");
// After loading, technique 0 and pass 0 should be auto-selected
EXPECT_EQ(editor->selectedTechniqueIndex(), 0);
EXPECT_EQ(editor->selectedPassIndex(), 0);
// Setting invalid indices should still work without crashing
editor->setSelectedTechniqueIndex(-1);
EXPECT_EQ(editor->selectedTechniqueIndex(), -1);
editor->setSelectedPassIndex(-1);
EXPECT_EQ(editor->selectedPassIndex(), -1);
editor->setSelectedTextureUnitIndex(-1);
EXPECT_EQ(editor->selectedTextureUnitIndex(), -1);
}
TEST_F(MaterialEditorQMLWithOgreTest, ApplyMaterial_Valid) {
editor->loadMaterial("BaseWhite");
QSignalSpy appliedSpy(editor.get(), &MaterialEditorQML::materialApplied);
// Apply the current (valid) material text
bool result = editor->applyMaterial();
EXPECT_TRUE(result);
EXPECT_GE(appliedSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, VertexColorTracking) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy spy(editor.get(), &MaterialEditorQML::useVertexColorToAmbientChanged);
editor->setUseVertexColorToAmbient(true);
EXPECT_GE(spy.count(), 1);
EXPECT_TRUE(editor->useVertexColorToAmbient());
editor->setUseVertexColorToDiffuse(true);
EXPECT_TRUE(editor->useVertexColorToDiffuse());
editor->setUseVertexColorToSpecular(true);
EXPECT_TRUE(editor->useVertexColorToSpecular());
editor->setUseVertexColorToEmissive(true);
EXPECT_TRUE(editor->useVertexColorToEmissive());
}
TEST_F(MaterialEditorQMLWithOgreTest, BlendFactors) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy srcSpy(editor.get(), &MaterialEditorQML::sourceBlendFactorChanged);
editor->setSourceBlendFactor(7); // One
EXPECT_GE(srcSpy.count(), 1);
QSignalSpy dstSpy(editor.get(), &MaterialEditorQML::destBlendFactorChanged);
// BaseWhite default dest blend is SBF_ZERO (enum 1) loaded as 1+1=2, so use a different value
editor->setDestBlendFactor(7); // SBF_SOURCE_ALPHA + 1
EXPECT_GE(dstSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, FogProperties) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setFogOverride(true);
EXPECT_TRUE(editor->fogOverride());
QSignalSpy fogModeSpy(editor.get(), &MaterialEditorQML::fogModeChanged);
editor->setFogMode(3); // Linear
EXPECT_GE(fogModeSpy.count(), 1);
editor->setFogDensity(0.5f);
EXPECT_FLOAT_EQ(editor->fogDensity(), 0.5f);
editor->setFogStart(10.0f);
EXPECT_FLOAT_EQ(editor->fogStart(), 10.0f);
editor->setFogEnd(100.0f);
EXPECT_FLOAT_EQ(editor->fogEnd(), 100.0f);
QColor fogCol(128, 64, 32);
editor->setFogColor(fogCol);
EXPECT_EQ(editor->fogColor(), fogCol);
}
TEST_F(MaterialEditorQMLWithOgreTest, DiffuseAlphaAndSpecularAlpha) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy diffAlphaSpy(editor.get(), &MaterialEditorQML::diffuseAlphaChanged);
editor->setDiffuseAlpha(0.5f);
EXPECT_GE(diffAlphaSpy.count(), 1);
EXPECT_FLOAT_EQ(editor->diffuseAlpha(), 0.5f);
QSignalSpy specAlphaSpy(editor.get(), &MaterialEditorQML::specularAlphaChanged);
editor->setSpecularAlpha(0.3f);
EXPECT_GE(specAlphaSpy.count(), 1);
EXPECT_FLOAT_EQ(editor->specularAlpha(), 0.3f);
}
TEST_F(MaterialEditorQMLWithOgreTest, TextureUnitOperations) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
// Create a texture unit
editor->createNewTextureUnit("TestTU");
EXPECT_FALSE(editor->textureUnitList().isEmpty());
// Select the texture unit
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
EXPECT_GE(editor->selectedTextureUnitIndex(), 0);
// Remove texture should reset texture name
editor->removeTexture();
EXPECT_EQ(editor->textureName(), "*Select a texture*");
}
TEST_F(MaterialEditorQMLWithOgreTest, DepthBias) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy constSpy(editor.get(), &MaterialEditorQML::depthBiasConstantChanged);
editor->setDepthBiasConstant(1.5f);
EXPECT_GE(constSpy.count(), 1);
EXPECT_FLOAT_EQ(editor->depthBiasConstant(), 1.5f);
QSignalSpy slopeSpy(editor.get(), &MaterialEditorQML::depthBiasSlopeScaleChanged);
editor->setDepthBiasSlopeScale(2.0f);
EXPECT_GE(slopeSpy.count(), 1);
EXPECT_FLOAT_EQ(editor->depthBiasSlopeScale(), 2.0f);
}
TEST_F(MaterialEditorQMLWithOgreTest, AlphaRejection) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setAlphaRejectionEnabled(true);
EXPECT_TRUE(editor->alphaRejectionEnabled());
editor->setAlphaRejectionFunction(2); // Less
EXPECT_EQ(editor->alphaRejectionFunction(), 2);
editor->setAlphaRejectionValue(128);
EXPECT_EQ(editor->alphaRejectionValue(), 128);
}
TEST_F(MaterialEditorQMLWithOgreTest, ColourWriteChannels) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setColourWriteRed(false);
EXPECT_FALSE(editor->colourWriteRed());
editor->setColourWriteGreen(false);
EXPECT_FALSE(editor->colourWriteGreen());
editor->setColourWriteBlue(false);
EXPECT_FALSE(editor->colourWriteBlue());
editor->setColourWriteAlpha(false);
EXPECT_FALSE(editor->colourWriteAlpha());
}
TEST_F(MaterialEditorQMLWithOgreTest, PointAndLineProperties) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setPointSize(3.0f);
EXPECT_FLOAT_EQ(editor->pointSize(), 3.0f);
editor->setLineWidth(2.0f);
EXPECT_FLOAT_EQ(editor->lineWidth(), 2.0f);
editor->setPointSpritesEnabled(true);
EXPECT_TRUE(editor->pointSpritesEnabled());
}
TEST_F(MaterialEditorQMLWithOgreTest, LightLimits) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setMaxLights(4);
EXPECT_EQ(editor->maxLights(), 4);
editor->setStartLight(1);
EXPECT_EQ(editor->startLight(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, DepthFunction) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
QSignalSpy spy(editor.get(), &MaterialEditorQML::depthFunctionChanged);
editor->setDepthFunction(2); // Less
EXPECT_GE(spy.count(), 1);
EXPECT_EQ(editor->depthFunction(), 2);
}
TEST_F(MaterialEditorQMLWithOgreTest, AlphaToCoverage) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->setAlphaToCoverageEnabled(true);
EXPECT_TRUE(editor->alphaToCoverageEnabled());
}
// ===========================================================================
// Texture transform setters (with Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLWithOgreTest, TextureUOffset) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("TexOffsetTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::textureUOffsetChanged);
editor->setTextureUOffset(0.5f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->textureUOffset(), 0.5f);
}
TEST_F(MaterialEditorQMLWithOgreTest, TextureVOffset) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("TexVOffsetTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::textureVOffsetChanged);
editor->setTextureVOffset(0.3f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->textureVOffset(), 0.3f);
}
TEST_F(MaterialEditorQMLWithOgreTest, TextureUScale) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("TexUScaleTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::textureUScaleChanged);
editor->setTextureUScale(2.0f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->textureUScale(), 2.0f);
}
TEST_F(MaterialEditorQMLWithOgreTest, TextureVScale) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("TexVScaleTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::textureVScaleChanged);
editor->setTextureVScale(3.0f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->textureVScale(), 3.0f);
}
TEST_F(MaterialEditorQMLWithOgreTest, TextureRotation) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("TexRotTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::textureRotationChanged);
editor->setTextureRotation(45.0f);
EXPECT_GE(spy.count(), 1);
EXPECT_FLOAT_EQ(editor->textureRotation(), 45.0f);
}
// ===========================================================================
// UV animation setters (with Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLWithOgreTest, ScrollAnimUSpeed) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("ScrollUTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::scrollAnimUSpeedChanged);
editor->setScrollAnimUSpeed(1.5);
EXPECT_GE(spy.count(), 1);
EXPECT_DOUBLE_EQ(editor->scrollAnimUSpeed(), 1.5);
}
TEST_F(MaterialEditorQMLWithOgreTest, ScrollAnimVSpeed) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("ScrollVTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::scrollAnimVSpeedChanged);
editor->setScrollAnimVSpeed(2.0);
EXPECT_GE(spy.count(), 1);
EXPECT_DOUBLE_EQ(editor->scrollAnimVSpeed(), 2.0);
}
TEST_F(MaterialEditorQMLWithOgreTest, RotateAnimSpeed) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("RotAnimTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::rotateAnimSpeedChanged);
editor->setRotateAnimSpeed(0.5);
EXPECT_GE(spy.count(), 1);
EXPECT_DOUBLE_EQ(editor->rotateAnimSpeed(), 0.5);
}
// ===========================================================================
// Environment mapping (with Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLWithOgreTest, EnvironmentMapping) {
editor->loadMaterial("BaseWhite");
ASSERT_FALSE(editor->passList().isEmpty());
editor->createNewTextureUnit("EnvMapTU");
editor->setSelectedTextureUnitIndex(editor->textureUnitList().size() - 1);
QSignalSpy spy(editor.get(), &MaterialEditorQML::environmentMappingChanged);
// Test None
editor->setEnvironmentMapping(0);
EXPECT_EQ(editor->environmentMapping(), 0);
// Test Planar
editor->setEnvironmentMapping(1);
EXPECT_EQ(editor->environmentMapping(), 1);
// Test Curved
editor->setEnvironmentMapping(2);
EXPECT_EQ(editor->environmentMapping(), 2);
EXPECT_GE(spy.count(), 2); // at least 2 changes (0->1, 1->2)
}
// ===========================================================================
// Export material (with Ogre)
// ===========================================================================
TEST_F(MaterialEditorQMLWithOgreTest, ExportMaterial_Valid) {
editor->loadMaterial("BaseWhite");
editor->exportMaterial("/tmp/test_matexport.material");
// Verify file was created
EXPECT_TRUE(QFile::exists("/tmp/test_matexport.material"));
QFile::remove("/tmp/test_matexport.material");
}
TEST_F(MaterialEditorQMLWithOgreTest, ExportMaterial_NoMaterial) {
QSignalSpy errorSpy(editor.get(), &MaterialEditorQML::errorOccurred);
// No material loaded — should emit error
editor->exportMaterial("/tmp/test_matexport_none.material");
EXPECT_GE(errorSpy.count(), 1);
}
TEST_F(MaterialEditorQMLWithOgreTest, ExportMaterial_ByName) {
editor->exportMaterial("/tmp/test_matexport_named.material", "BaseWhite");
EXPECT_TRUE(QFile::exists("/tmp/test_matexport_named.material"));
QFile::remove("/tmp/test_matexport_named.material");
}
TEST_F(MaterialEditorQMLWithOgreTest, ExportMaterial_ByNameNotFound) {