-
Notifications
You must be signed in to change notification settings - Fork 492
Expand file tree
/
Copy pathConfig_tests.cpp
More file actions
10417 lines (8495 loc) · 385 KB
/
Config_tests.cpp
File metadata and controls
10417 lines (8495 loc) · 385 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
// SPDX-License-Identifer: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.
#include <sys/stat.h>
#include <pystring.h>
#include "Config.cpp"
#include "testutils/UnitTest.h"
#include "UnitTestLogUtils.h"
#include "UnitTestUtils.h"
#include "utils/StringUtils.h"
#include "Platform.h"
namespace OCIO = OCIO_NAMESPACE;
#if 0
OCIO_ADD_TEST(Config, test_searchpath_filesystem)
{
OCIO::EnvMap env = OCIO::GetEnvMap();
std::string OCIO_TEST_AREA("$OCIO_TEST_AREA");
EnvExpand(&OCIO_TEST_AREA, &env);
OCIO::ConfigRcPtr config = OCIO::Config::Create();
// basic get/set/expand
config->setSearchPath("."
":$OCIO_TEST1"
":/$OCIO_JOB/${OCIO_SEQ}/$OCIO_SHOT/ocio");
OCIO_CHECK_ASSERT(strcmp(config->getSearchPath(),
".:$OCIO_TEST1:/$OCIO_JOB/${OCIO_SEQ}/$OCIO_SHOT/ocio") == 0);
OCIO_CHECK_ASSERT(strcmp(config->getSearchPath(true),
".:foobar:/meatballs/cheesecake/mb-cc-001/ocio") == 0);
// find some files
config->setSearchPath(".."
":$OCIO_TEST1"
":${OCIO_TEST_AREA}/test_search/one"
":$OCIO_TEST_AREA/test_search/two");
// setup for search test
std::string base_dir("$OCIO_TEST_AREA/test_search/");
EnvExpand(&base_dir, &env);
mkdir(base_dir.c_str(), 0777);
std::string one_dir("$OCIO_TEST_AREA/test_search/one/");
EnvExpand(&one_dir, &env);
mkdir(one_dir.c_str(), 0777);
std::string two_dir("$OCIO_TEST_AREA/test_search/two/");
EnvExpand(&two_dir, &env);
mkdir(two_dir.c_str(), 0777);
std::string lut1(one_dir+"somelut1.lut");
std::ofstream somelut1(lut1.c_str());
somelut1.close();
std::string lut2(two_dir+"somelut2.lut");
std::ofstream somelut2(lut2.c_str());
somelut2.close();
std::string lut3(two_dir+"somelut3.lut");
std::ofstream somelut3(lut3.c_str());
somelut3.close();
std::string lutdotdot(OCIO_TEST_AREA+"/lutdotdot.lut");
std::ofstream somelutdotdot(lutdotdot.c_str());
somelutdotdot.close();
// basic search test
OCIO_CHECK_ASSERT(strcmp(config->findFile("somelut1.lut"),
lut1.c_str()) == 0);
OCIO_CHECK_ASSERT(strcmp(config->findFile("somelut2.lut"),
lut2.c_str()) == 0);
OCIO_CHECK_ASSERT(strcmp(config->findFile("somelut3.lut"),
lut3.c_str()) == 0);
OCIO_CHECK_ASSERT(strcmp(config->findFile("lutdotdot.lut"),
lutdotdot.c_str()) == 0);
}
#endif
OCIO_ADD_TEST(Config, internal_raw_profile)
{
std::istringstream is;
is.str(OCIO::INTERNAL_RAW_PROFILE);
OCIO_CHECK_NO_THROW(OCIO::Config::CreateFromStream(is));
}
OCIO_ADD_TEST(Config, create_raw_config)
{
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateRaw());
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_EQUAL(config->getNumColorSpaces(), 1);
OCIO_CHECK_EQUAL(std::string(config->getColorSpaceNameByIndex(0)), std::string("raw"));
OCIO::ConstProcessorRcPtr proc;
OCIO_CHECK_NO_THROW(proc = config->getProcessor("raw", "raw"));
OCIO_CHECK_NO_THROW(proc->getDefaultCPUProcessor());
OCIO_CHECK_THROW_WHAT(config->getProcessor("not_found", "raw"), OCIO::Exception,
"Color space 'not_found' could not be found");
OCIO_CHECK_THROW_WHAT(config->getProcessor("raw", "not_found"), OCIO::Exception,
"Color space 'not_found' could not be found");
}
OCIO_ADD_TEST(Config, simple_config)
{
constexpr char SIMPLE_PROFILE[] =
"ocio_profile_version: 1\n"
"resource_path: luts\n"
"strictparsing: false\n"
"luma: [0.2126, 0.7152, 0.0722]\n"
"roles:\n"
" default: raw\n"
" scene_linear: lnh\n"
"displays:\n"
" sRGB:\n"
" - !<View> {name: Film1D, colorspace: loads_of_transforms}\n"
" - !<View> {name: Ln, colorspace: lnh}\n"
" - !<View> {name: Raw, colorspace: raw}\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
" family: raw\n"
" equalitygroup: \n"
" bitdepth: 32f\n"
" description: |\n"
" A raw color space. Conversions to and from this space are no-ops.\n"
" isdata: true\n"
" allocation: uniform\n"
" - !<ColorSpace>\n"
" name: lnh\n"
" family: ln\n"
" equalitygroup: \n"
" bitdepth: 16f\n"
" description: |\n"
" The show reference space. This is a sensor referred linear\n"
" representation of the scene with primaries that correspond to\n"
" scanned film. 0.18 in this space corresponds to a properly\n"
" exposed 18% grey card.\n"
" isdata: false\n"
" allocation: lg2\n"
" - !<ColorSpace>\n"
" name: loads_of_transforms\n"
" family: vd8\n"
" equalitygroup: \n"
" bitdepth: 8ui\n"
" description: 'how many transforms can we use?'\n"
" isdata: false\n"
" allocation: uniform\n"
" to_reference: !<GroupTransform>\n"
" direction: forward\n"
" children:\n"
" - !<FileTransform>\n"
" src: diffusemult.spimtx\n"
" interpolation: unknown\n"
" - !<ColorSpaceTransform>\n"
" src: raw\n"
" dst: lnh\n"
" - !<ExponentTransform>\n"
" value: [2.2, 2.2, 2.2, 1]\n"
" - !<MatrixTransform>\n"
" matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\n"
" offset: [0, 0, 0, 0]\n"
" - !<CDLTransform>\n"
" slope: [1, 1, 1]\n"
" offset: [0, 0, 0]\n"
" power: [1, 1, 1]\n"
" saturation: 1\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_NO_THROW(config->validate());
}
OCIO_ADD_TEST(Config, colorspace_duplicate)
{
constexpr char SIMPLE_PROFILE[] =
"ocio_profile_version: 2\n"
"search_path: luts\n"
"roles:\n"
" default: raw\n"
"file_rules:\n"
" - !<Rule> {name: Default, colorspace: default}\n"
"displays:\n"
" Disp1:\n"
" - !<View> {name: View1, colorspace: raw}\n"
"active_displays: []\n"
"active_views: []\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw_duplicated\n"
" name: raw\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(is), OCIO::Exception,
"Key-value pair with key 'name' specified more than once. ");
}
OCIO_ADD_TEST(Config, cdltransform_duplicate)
{
constexpr char SIMPLE_PROFILE[] =
"ocio_profile_version: 2\n"
"search_path: luts\n"
"roles:\n"
" default: raw\n"
"file_rules:\n"
" - !<Rule> {name: Default, colorspace: default}\n"
"displays:\n"
" Disp1:\n"
" - !<View> {name: View1, colorspace: raw}\n"
"active_displays: []\n"
"active_views: []\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
" to_scene_reference: !<CDLTransform> {slope: [1, 2, 1], slope: [1, 2, 1]}\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(is), OCIO::Exception,
"Key-value pair with key 'slope' specified more than once. ");
}
OCIO_ADD_TEST(Config, searchpath_duplicate)
{
constexpr char SIMPLE_PROFILE[] =
"ocio_profile_version: 2\n"
"search_path: luts\n"
"search_path: luts-dir\n"
"roles:\n"
" default: raw\n"
"file_rules:\n"
" - !<Rule> {name: Default, colorspace: default}\n"
"displays:\n"
" Disp1:\n"
" - !<View> {name: View1, colorspace: raw}\n"
"active_displays: []\n"
"active_views: []\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(is), OCIO::Exception,
"Key-value pair with key 'search_path' specified more than once. ");
}
OCIO_ADD_TEST(Config, roles)
{
std::string SIMPLE_PROFILE =
"ocio_profile_version: 1\n"
"strictparsing: false\n"
"roles:\n"
" compositing_log: lgh\n"
" default: raw\n"
" scene_linear: lnh\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
" - !<ColorSpace>\n"
" name: lnh\n"
" - !<ColorSpace>\n"
" name: lgh\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_EQUAL(config->getNumRoles(), 3);
OCIO_CHECK_ASSERT(config->hasRole("compositing_log"));
OCIO_CHECK_ASSERT(!config->hasRole("cheese"));
OCIO_CHECK_ASSERT(!config->hasRole(""));
OCIO_CHECK_EQUAL(std::string(config->getRoleName(2)), "scene_linear");
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(2)), "lnh");
OCIO_CHECK_EQUAL(std::string(config->getRoleName(0)), "compositing_log");
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(0)), "lgh");
OCIO_CHECK_EQUAL(std::string(config->getRoleName(1)), "default");
OCIO_CHECK_EQUAL(std::string(config->getRoleName(10)), "");
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(10)), "");
OCIO_CHECK_EQUAL(std::string(config->getRoleName(-4)), "");
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(-4)), "");
// Test existing roles.
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("scene_linear")), std::string("lnh"));
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("compositing_log")), std::string("lgh"));
// Test a unknown role.
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("wrong_role")), std::string(""));
// Test an empty input.
OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("")), std::string(""));
}
OCIO_ADD_TEST(Config, required_roles_for_version_2_2)
{
// Test Setup
OCIO::ConfigRcPtr config = OCIO::Config::Create();
// Add default color space for file rules.
auto cs = OCIO::ColorSpace::Create(OCIO::REFERENCE_SPACE_SCENE);
cs->setName("default");
config->addColorSpace(cs);
// Add a simple view.
const std::string display{ "display" };
OCIO_CHECK_NO_THROW(config->addDisplayView(display.c_str(), "view1", "default", ""));
// Add a scene-referred color space.
auto scs = OCIO::ColorSpace::Create(OCIO::REFERENCE_SPACE_SCENE);
scs->setName("scs");
config->addColorSpace(scs);
// Add a display-referred color space.
auto dcs = OCIO::ColorSpace::Create(OCIO::REFERENCE_SPACE_DISPLAY);
dcs->setName("dcs");
config->addColorSpace(dcs);
auto vt = OCIO::ViewTransform::Create(OCIO::REFERENCE_SPACE_SCENE);
vt->setName("view_transform");
OCIO_CHECK_NO_THROW(vt->setTransform(OCIO::MatrixTransform::Create(),
OCIO::VIEWTRANSFORM_DIR_FROM_REFERENCE));
OCIO_CHECK_NO_THROW(config->addViewTransform(vt));
// End of setup.
// Interchange roles tests
{
// Test that the config version is >= 2.2.
OCIO_CHECK_GE(config->getMajorVersion(), 2);
OCIO_CHECK_GE(config->getMinorVersion(), 2);
}
{
// Test that all errors appear when all required roles are missing.
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
// Check that the log contains the expected error messages for the missing roles and mute
// them so that (only) those messages don't appear in the test output.
OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard));
OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard));
OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard));
OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard));
OCIO_CHECK_ASSERT(OCIO::checkAndMuteDisplayInterchangeRoleError(logGuard));
// If there are any unexpected log messages, print them to the shell.
logGuard.print();
}
// Set colorspace for all required roles.
config->setRole(OCIO::ROLE_SCENE_LINEAR, scs->getName());
config->setRole(OCIO::ROLE_COMPOSITING_LOG, dcs->getName());
config->setRole(OCIO::ROLE_COLOR_TIMING, dcs->getName());
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, scs->getName());
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, dcs->getName());
{
// Check that no warning is logged when all required roles are set.
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_ASSERT(logGuard.empty());
}
{
// Test that scene_linear role is missing.
// Unset scene_linear role.
config->setRole(OCIO::ROLE_SCENE_LINEAR, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output());
OCIO_CHECK_ASSERT(
StringUtils::Contain(
svec,
"[OpenColorIO Error]: The scene_linear role is required for a config version 2.2 or"\
" higher.")
);
// Set scene_linear for next test.
config->setRole(OCIO::ROLE_SCENE_LINEAR, dcs->getName());
}
{
// Test that compositing_log role is missing.
// Unset compositing_log role.
config->setRole(OCIO::ROLE_COMPOSITING_LOG, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output());
checkAndMuteCompositingLogRoleError(logGuard);
// Set compositing_log for next test.
config->setRole(OCIO::ROLE_COMPOSITING_LOG, dcs->getName());
}
{
// Test that color_timing role is missing.
// Unset color_timing role.
config->setRole(OCIO::ROLE_COLOR_TIMING, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output());
checkAndMuteColorTimingRoleError(logGuard);
// Set color_timing for next test.
config->setRole(OCIO::ROLE_COLOR_TIMING, dcs->getName());
}
{
// Test that aces_interchange role is missing.
// Unset aces_interchange role.
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO::checkAndMuteAcesInterchangeRoleError(logGuard);
// Set aces_interchange for next test.
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, scs->getName());
}
{
// Test that cie_xyz_d65_interchange role is missing.
// Unset cie_xyz_d65_interchange role.
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO::checkAndMuteDisplayInterchangeRoleError(logGuard);
// Set cie_xyz_d65_interchange for next test.
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, dcs->getName());
}
{
// Test detection of the aces_interchange role having the wrong colorspace type.
// Set a display-referred colorspace to both interchange roles.
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, dcs->getName());
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, dcs->getName());
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_ASSERT(
StringUtils::StartsWith(
logGuard.output(),
"[OpenColorIO Error]: The aces_interchange role must be a scene-referred color space.")
);
}
{
// Test detection of the cie_xyz_d65_interchange role having the wrong colorspace type.
// Set a scene-referred colorspace to both interchange roles.
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, scs->getName());
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, scs->getName());
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_ASSERT(
StringUtils::StartsWith(
logGuard.output(),
"[OpenColorIO Error]: The cie_xyz_d65_interchange role must be a display-referred color space.")
);
}
{
// Set the config to 2.1, delete the roles and check that no warning is logged.
OCIO_CHECK_NO_THROW(config->setMajorVersion(2));
OCIO_CHECK_NO_THROW(config->setMinorVersion(1));
// Unset all required roles
config->setRole(OCIO::ROLE_SCENE_LINEAR, nullptr);
config->setRole(OCIO::ROLE_COMPOSITING_LOG, nullptr);
config->setRole(OCIO::ROLE_COLOR_TIMING, nullptr);
config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, nullptr);
config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, nullptr);
OCIO::LogGuard logGuard;
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_ASSERT(logGuard.empty());
}
}
OCIO_ADD_TEST(Config, serialize_group_transform)
{
// The unit test validates that a group transform is correctly serialized.
OCIO::ConfigRcPtr config = OCIO::Config::Create();
{
OCIO::ColorSpaceRcPtr cs = OCIO::ColorSpace::Create();
cs->setName("testing");
cs->setFamily("test");
OCIO::GroupTransformRcPtr groupTransform = OCIO::GroupTransform::Create();
// Default and unknown interpolation are not saved.
OCIO::FileTransformRcPtr transform1 = OCIO::FileTransform::Create();
groupTransform->appendTransform(transform1);
OCIO::FileTransformRcPtr transform2 = OCIO::FileTransform::Create();
transform2->setInterpolation(OCIO::INTERP_UNKNOWN);
groupTransform->appendTransform(transform2);
OCIO::FileTransformRcPtr transform3 = OCIO::FileTransform::Create();
transform3->setInterpolation(OCIO::INTERP_BEST);
groupTransform->appendTransform(transform3);
OCIO::FileTransformRcPtr transform4 = OCIO::FileTransform::Create();
transform4->setInterpolation(OCIO::INTERP_NEAREST);
groupTransform->appendTransform(transform4);
OCIO::FileTransformRcPtr transform5 = OCIO::FileTransform::Create();
transform5->setInterpolation(OCIO::INTERP_CUBIC);
groupTransform->appendTransform(transform5);
OCIO_CHECK_NO_THROW(cs->setTransform(groupTransform, OCIO::COLORSPACE_DIR_FROM_REFERENCE));
config->addColorSpace(cs);
config->setRole( OCIO::ROLE_DEFAULT, cs->getName() );
config->setRole(OCIO::ROLE_COMPOSITING_LOG, cs->getName());
}
{
OCIO::ColorSpaceRcPtr cs = OCIO::ColorSpace::Create();
cs->setName("testing2");
cs->setFamily("test");
OCIO::ExponentTransformRcPtr transform1 = OCIO::ExponentTransform::Create();
OCIO::GroupTransformRcPtr groupTransform = OCIO::GroupTransform::Create();
groupTransform->appendTransform(transform1);
OCIO_CHECK_NO_THROW(cs->setTransform(groupTransform, OCIO::COLORSPACE_DIR_TO_REFERENCE));
config->addColorSpace(cs);
// Replace the role.
config->setRole( OCIO::ROLE_COMPOSITING_LOG, cs->getName() );
}
config->setVersion(2, 2);
std::ostringstream os;
config->serialize(os);
std::string PROFILE_OUT =
"ocio_profile_version: 2.2\n"
"\n"
"environment:\n"
" {}\n"
"search_path: \"\"\n"
"strictparsing: true\n"
"luma: [0.2126, 0.7152, 0.0722]\n"
"\n"
"roles:\n"
" compositing_log: testing2\n"
" default: testing\n"
"\n"
"file_rules:\n"
" - !<Rule> {name: Default, colorspace: default}\n"
"\n"
"displays:\n"
" {}\n"
"\n"
"active_displays: []\n"
"active_views: []\n"
"\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: testing\n"
" family: test\n"
" equalitygroup: \"\"\n"
" bitdepth: unknown\n"
" isdata: false\n"
" allocation: uniform\n"
" from_scene_reference: !<GroupTransform>\n"
" children:\n"
" - !<FileTransform> {src: \"\"}\n"
" - !<FileTransform> {src: \"\", interpolation: unknown}\n"
" - !<FileTransform> {src: \"\", interpolation: best}\n"
" - !<FileTransform> {src: \"\", interpolation: nearest}\n"
" - !<FileTransform> {src: \"\", interpolation: cubic}\n"
"\n"
" - !<ColorSpace>\n"
" name: testing2\n"
" family: test\n"
" equalitygroup: \"\"\n"
" bitdepth: unknown\n"
" isdata: false\n"
" allocation: uniform\n"
" to_scene_reference: !<GroupTransform>\n"
" children:\n"
" - !<ExponentTransform> {value: 1}\n";
const StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
const StringUtils::StringVec PROFILE_OUTvec = StringUtils::SplitByLines(PROFILE_OUT);
OCIO_CHECK_EQUAL(osvec.size(), PROFILE_OUTvec.size());
for (unsigned int i = 0; i < PROFILE_OUTvec.size(); ++i)
{
OCIO_CHECK_EQUAL(osvec[i], PROFILE_OUTvec[i]);
}
}
OCIO_ADD_TEST(Config, serialize_searchpath)
{
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
{
OCIO::ColorSpaceRcPtr cs = OCIO::ColorSpace::Create();
cs->setName("default");
cs->setIsData(true);
config->addColorSpace(cs);
config->setVersion(2, 2);
}
std::ostringstream os;
config->serialize(os);
std::string PROFILE_OUT =
"ocio_profile_version: 2.2\n"
"\n"
"environment:\n"
" {}\n"
"search_path: \"\"\n"
"strictparsing: true\n"
"luma: [0.2126, 0.7152, 0.0722]\n"
"\n"
"roles:\n"
" {}\n"
"\n"
"file_rules:\n"
" - !<Rule> {name: Default, colorspace: default}\n"
"\n"
"displays:\n"
" {}\n"
"\n"
"active_displays: []\n"
"active_views: []\n"
"\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: default\n"
" family: \"\"\n"
" equalitygroup: \"\"\n"
" bitdepth: unknown\n"
" isdata: true\n"
" allocation: uniform\n";
const StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
const StringUtils::StringVec PROFILE_OUTvec = StringUtils::SplitByLines(PROFILE_OUT);
OCIO_CHECK_EQUAL(osvec.size(), PROFILE_OUTvec.size());
for (unsigned int i = 0; i < PROFILE_OUTvec.size(); ++i)
OCIO_CHECK_EQUAL(osvec[i], PROFILE_OUTvec[i]);
}
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(OCIO::FirstSupportedMajorVersion);
config->setMinorVersion(0);
std::string searchPath("a:b:c");
config->setSearchPath(searchPath.c_str());
std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
// V1 saves search_path as a single string.
const std::string expected1{ "search_path: a:b:c" };
OCIO_CHECK_EQUAL(osvec[2], expected1);
// V2 saves search_path as separate strings.
config->setMajorVersion(2);
os.clear();
os.str("");
config->serialize(os);
osvec = StringUtils::SplitByLines(os.str());
const std::string expected2[] = { "search_path:", " - a", " - b", " - c" };
OCIO_CHECK_EQUAL(osvec[4], expected2[0]);
OCIO_CHECK_EQUAL(osvec[5], expected2[1]);
OCIO_CHECK_EQUAL(osvec[6], expected2[2]);
OCIO_CHECK_EQUAL(osvec[7], expected2[3]);
std::istringstream is;
is.str(os.str());
OCIO::ConstConfigRcPtr configRead;
OCIO_CHECK_NO_THROW(configRead = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_EQUAL(configRead->getNumSearchPaths(), 3);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath()), searchPath);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(0)), std::string("a"));
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(1)), std::string("b"));
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(2)), std::string("c"));
os.clear();
os.str("");
config->clearSearchPaths();
const std::string sp0{ "a path with a - in it/" };
const std::string sp1{ "/absolute/linux/path" };
const std::string sp2{ "C:\\absolute\\windows\\path" };
const std::string sp3{ "!<path> using /yaml/symbols" };
config->addSearchPath(sp0.c_str());
config->addSearchPath(sp1.c_str());
config->addSearchPath(sp2.c_str());
config->addSearchPath(sp3.c_str());
config->serialize(os);
osvec = StringUtils::SplitByLines(os.str());
const std::string expected3[] = { "search_path:",
" - a path with a - in it/",
" - /absolute/linux/path",
" - C:\\absolute\\windows\\path",
" - \"!<path> using /yaml/symbols\"" };
OCIO_CHECK_EQUAL(osvec[4], expected3[0]);
OCIO_CHECK_EQUAL(osvec[5], expected3[1]);
OCIO_CHECK_EQUAL(osvec[6], expected3[2]);
OCIO_CHECK_EQUAL(osvec[7], expected3[3]);
OCIO_CHECK_EQUAL(osvec[8], expected3[4]);
is.clear();
is.str(os.str());
OCIO_CHECK_NO_THROW(configRead = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_EQUAL(configRead->getNumSearchPaths(), 4);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(0)), sp0);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(1)), sp1);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(2)), sp2);
OCIO_CHECK_EQUAL(std::string(configRead->getSearchPath(3)), sp3);
}
}
OCIO_ADD_TEST(Config, serialize_environment)
{
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(1);
config->setMinorVersion(0);
std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
// A v1 config does not write the environment section if it's empty.
const std::string expected{ "search_path: \"\"" };
OCIO_CHECK_EQUAL(osvec[2], expected);
}
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(2);
config->setMinorVersion(0);
std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
// A v2 config does write the environment section, even if it's empty.
const std::string expected1{ "environment:" };
const std::string expected2{ " {}" };
OCIO_CHECK_EQUAL(osvec[2], expected1);
OCIO_CHECK_EQUAL(osvec[3], expected2);
}
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(1);
config->setMinorVersion(0);
config->addEnvironmentVar("SHOT", "0001");
std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());
// A v1 config does write the environment section if it's not empty.
const std::string expected1{ "environment:" };
const std::string expected2{ " SHOT: 0001" };
OCIO_CHECK_EQUAL(osvec[2], expected1);
OCIO_CHECK_EQUAL(osvec[3], expected2);
}
}
OCIO_ADD_TEST(Config, validation)
{
{
std::string SIMPLE_PROFILE =
"ocio_profile_version: 1\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
" - !<ColorSpace>\n"
" name: raw\n"
"strictparsing: false\n"
"roles:\n"
" default: raw\n"
"displays:\n"
" sRGB:\n"
" - !<View> {name: Raw, colorspace: raw}\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(is), OCIO::Exception,
"Colorspace with name 'raw' already defined");
}
{
std::string SIMPLE_PROFILE =
"ocio_profile_version: 1\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
"strictparsing: false\n"
"roles:\n"
" default: raw\n"
"displays:\n"
" sRGB:\n"
" - !<View> {name: Raw, colorspace: raw}\n"
"\n";
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_NO_THROW(config->validate());
}
}
OCIO_ADD_TEST(Config, context_variable_v1)
{
std::string SIMPLE_PROFILE =
"ocio_profile_version: 1\n"
"environment:\n"
" SHOW: super\n"
" SHOT: test\n"
" SEQ: foo\n"
" test: bar${cheese}\n"
" cheese: chedder\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
"strictparsing: false\n"
"roles:\n"
" default: raw\n"
"displays:\n"
" sRGB:\n"
" - !<View> {name: Raw, colorspace: raw}\n"
"\n";
std::string SIMPLE_PROFILE2 =
"ocio_profile_version: 1\n"
"colorspaces:\n"
" - !<ColorSpace>\n"
" name: raw\n"
"strictparsing: false\n"
"roles:\n"
" default: raw\n"
"displays:\n"
" sRGB:\n"
" - !<View> {name: Raw, colorspace: raw}\n"
"\n";
OCIO::EnvironmentVariableGuard guardShow("SHOW", "bar");
OCIO::EnvironmentVariableGuard guardTask("TASK", "lighting");
std::istringstream is;
is.str(SIMPLE_PROFILE);
OCIO::ConstConfigRcPtr config;
OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_NO_THROW(config->validate());
OCIO_CHECK_EQUAL(config->getNumEnvironmentVars(), 5);
OCIO::ContextRcPtr usedContextVars = OCIO::Context::Create();
// Test context variable resolution.
OCIO_CHECK_EQUAL(0, strcmp(config->getCurrentContext()->resolveStringVar("test${test}",
usedContextVars),
"testbarchedder"));
OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars());
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarNameByIndex(0), "cheese"));
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarByIndex(0), "chedder"));
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarNameByIndex(1), "test"));
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarByIndex(1), "bar${cheese}"));
usedContextVars->clearStringVars();
OCIO_CHECK_EQUAL(0, strcmp(config->getCurrentContext()->resolveStringVar("${SHOW}",
usedContextVars),
"bar"));
OCIO_CHECK_EQUAL(1, usedContextVars->getNumStringVars());
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarNameByIndex(0), "SHOW"));
OCIO_CHECK_EQUAL(0, strcmp(usedContextVars->getStringVarByIndex(0), "bar"));
// Even if an environment variable overrides $SHOW, its default value is still "super".
OCIO_CHECK_ASSERT(strcmp(config->getEnvironmentVarDefault("SHOW"), "super") == 0);
// Test default context variables.
OCIO::ConfigRcPtr edit = config->createEditableCopy();
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 5);
edit->clearEnvironmentVars();
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 0);
edit->addEnvironmentVar("testing", "dupvar");
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 1);
edit->addEnvironmentVar("testing", "dupvar"); // No duplications.
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 1);
edit->addEnvironmentVar("foobar", "testing");
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 2);
edit->addEnvironmentVar("blank", "");
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 3);
edit->addEnvironmentVar("dontadd", nullptr);
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 3);
edit->addEnvironmentVar("foobar", nullptr); // Remove an entry.
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 2);
edit->clearEnvironmentVars();
OCIO_CHECK_EQUAL(edit->getNumEnvironmentVars(), 0);
OCIO_CHECK_EQUAL(edit->getEnvironmentMode(), OCIO::ENV_ENVIRONMENT_LOAD_PREDEFINED);
OCIO_CHECK_NO_THROW(edit->setEnvironmentMode(OCIO::ENV_ENVIRONMENT_LOAD_ALL));
OCIO_CHECK_EQUAL(edit->getEnvironmentMode(), OCIO::ENV_ENVIRONMENT_LOAD_ALL);
// Test the second config i.e. not in predefined mode.
// As a debug message is expected, trap & check its content.
OCIO::LogGuard log;
is.str(SIMPLE_PROFILE2);
OCIO::ConstConfigRcPtr noenv;
OCIO_CHECK_NO_THROW(noenv = OCIO::Config::CreateFromStream(is));
OCIO_CHECK_NO_THROW(noenv->validate());
OCIO_CHECK_EQUAL(noenv->getEnvironmentMode(), OCIO::ENV_ENVIRONMENT_LOAD_ALL);
// In all mode, use all system env. variables as potential context variables.
OCIO_CHECK_ASSERT(strcmp(noenv->getCurrentContext()->resolveStringVar("${TASK}"),
"lighting") == 0);
OCIO_CHECK_EQUAL(log.output(),
"[OpenColorIO Debug]: This .ocio config has no environment section defined."
" The default behaviour is to load all environment variables (0), which reduces"
" the efficiency of OCIO's caching. Consider predefining the environment"
" variables used.\n");
}
OCIO_ADD_TEST(Config, context_variable_faulty_cases)
{
// Check that all transforms using color space names correctly support the context variable
// validation.
static constexpr char CONFIG[] =
"ocio_profile_version: 2\n"
"\n"
"search_path: luts\n"
"\n"
"environment:\n"
" DST1: cs2\n"
" DST2: cs2\n"
" DST3: cs2\n"
"\n"
"roles:\n"
" default: cs1\n"
"\n"
"view_transforms:\n"