Debian Codegraph @

lib/Alembic/AbcCoreHDF5/Tests/ScalarPropertyTests.cpp

raw
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
4 // Sony Pictures Imageworks Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic, nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36
37 #include <Alembic/AbcCoreAbstract/All.h>
38 #include <Alembic/AbcCoreHDF5/All.h>
39 #include <Alembic/Util/All.h>
40
41 #include <Alembic/AbcCoreAbstract/Tests/Assert.h>
42
43 #include <iostream>
44 #include <vector>
45
46 #include <hdf5.h>
47
48 //-*****************************************************************************
49 namespace A5 = Alembic::AbcCoreHDF5;
50
51 namespace AbcA = Alembic::AbcCoreAbstract;
52
53 //-*****************************************************************************
54 void testWeirdStringScalar()
55 {
56 std::string archiveName = "weirdStr.abc";
57
58 Alembic::Util::string weirdStr = "Total failure";
59 weirdStr[5] = '\0';
60
61 Alembic::Util::wstring weirdWstr = L"Failure is always an option";
62 weirdWstr[5] = L'\0';
63
64 std::vector < Alembic::Util::string > weirdStrArray(3);
65 weirdStrArray[0] = "watch";
66 weirdStrArray[1] = "this";
67 weirdStrArray[2] = "please";
68 weirdStrArray[2][3] = '\0';
69
70 Alembic::Util::string empty;
71 Alembic::Util::wstring wempty;
72
73 std::vector < Alembic::Util::string > allEmptyStr(3);
74
75 std::vector < Alembic::Util::string > partEmptyStr(6);
76 partEmptyStr[0] = "";
77 partEmptyStr[1] = "";
78 partEmptyStr[2] = "notEmpty!";
79 partEmptyStr[3] = "";
80 partEmptyStr[4] = "also not empty";
81 partEmptyStr[5] = "";
82
83 {
84 A5::WriteArchive w;
85 AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData());
86 AbcA::ObjectWriterPtr archive = a->getTop();
87
88 AbcA::CompoundPropertyWriterPtr props = archive->getProperties();
89
90 {
91
92 AbcA::ScalarPropertyWriterPtr emptyWrtPtr =
93 props->createScalarProperty("empty", AbcA::MetaData(),
94 AbcA::DataType(Alembic::Util::kStringPOD, 1), 0);
95
96 // this should fail because of the NULL char in the string
97 TESTING_ASSERT_THROW(emptyWrtPtr->setSample(&weirdStr),
98 Alembic::Util::Exception);
99
100 emptyWrtPtr->setSample(&empty);
101
102 AbcA::ScalarPropertyWriterPtr wemptyWrtPtr =
103 props->createScalarProperty("wempty", AbcA::MetaData(),
104 AbcA::DataType(Alembic::Util::kWstringPOD, 1), 0);
105
106 // this should fail because of the NULL char in the string
107 TESTING_ASSERT_THROW(wemptyWrtPtr->setSample(&weirdWstr),
108 Alembic::Util::Exception);
109
110 wemptyWrtPtr->setSample(&wempty);
111
112
113 AbcA::ScalarPropertyWriterPtr allEmptyWrtPtr =
114 props->createScalarProperty("allEmpty", AbcA::MetaData(),
115 AbcA::DataType(Alembic::Util::kStringPOD, 3), 0);
116
117 // one of the strings has a NULL char in it
118 TESTING_ASSERT_THROW(
119 allEmptyWrtPtr->setSample(&(weirdStrArray.front())),
120 Alembic::Util::Exception);
121
122 allEmptyWrtPtr->setSample(&(allEmptyStr.front()));
123
124 AbcA::ScalarPropertyWriterPtr partEmptyStrPtr =
125 props->createScalarProperty("partEmpty", AbcA::MetaData(),
126 AbcA::DataType(Alembic::Util::kStringPOD, 6), 0);
127
128 partEmptyStrPtr->setSample(&(partEmptyStr.front()));
129 }
130 }
131
132 {
133 A5::ReadArchive r;
134 AbcA::ArchiveReaderPtr a = r( archiveName );
135 AbcA::ObjectReaderPtr archive = a->getTop();
136 AbcA::CompoundPropertyReaderPtr parent = archive->getProperties();
137
138 for (size_t i = 0; i < parent->getNumProperties(); ++i)
139 {
140 AbcA::BasePropertyReaderPtr bp = parent->getProperty( i );
141 if (bp->getName() == "partEmpty")
142 {
143 std::vector < Alembic::Util::string > val (6);
144 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
145 TESTING_ASSERT(sp->getDataType().getExtent() == 6);
146 sp->getSample(0, &(val.front()));
147 TESTING_ASSERT(val == partEmptyStr);
148 }
149 else if (bp->getName() == "allEmpty")
150 {
151 std::vector < Alembic::Util::string > val (3);
152 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
153 TESTING_ASSERT(sp->getDataType().getExtent() == 3);
154 sp->getSample(0, &(val.front()));
155 TESTING_ASSERT(val == allEmptyStr);
156 }
157 else if (bp->getName() == "empty")
158 {
159 Alembic::Util::string val;
160 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
161 sp->getSample(0, &val);
162 TESTING_ASSERT(val == empty);
163 }
164 else if (bp->getName() == "wempty")
165 {
166 Alembic::Util::wstring val;
167 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
168 sp->getSample(0, &val);
169 TESTING_ASSERT(val == wempty);
170 }
171 else
172 {
173 TESTING_ASSERT(false);
174 }
175 }
176
177 }
178 }
179
180 //-*****************************************************************************
181 void testReadWriteScalars()
182 {
183
184 std::string archiveName = "staticProperties.abc";
185
186 {
187 A5::WriteArchive w;
188 AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData());
189 AbcA::ObjectWriterPtr archive = a->getTop();
190
191 AbcA::CompoundPropertyWriterPtr props = archive->getProperties();
192
193 const AbcA::TimeSamplingType staticSampling;
194
195 {
196 AbcA::DataType dtype(Alembic::Util::kUint8POD, 1);
197 TESTING_ASSERT_THROW(props->createScalarProperty("/slashy",
198 AbcA::MetaData(), dtype, 0 ), Alembic::Util::Exception);
199 }
200
201 {
202 AbcA::ScalarPropertyWriterPtr boolWrtPtr =
203 props->createScalarProperty("bool", AbcA::MetaData(),
204 AbcA::DataType(Alembic::Util::kBooleanPOD, 1), 0);
205 Alembic::Util::bool_t b = true;
206 boolWrtPtr->setSample(&b);
207 }
208
209
210 {
211 AbcA::ScalarPropertyWriterPtr ucharWrtPtr =
212 props->createScalarProperty("uchar", AbcA::MetaData(),
213 AbcA::DataType(Alembic::Util::kUint8POD, 1), 0);
214
215 Alembic::Util::uint8_t uc = 200;
216
217 TESTING_ASSERT(ucharWrtPtr->getNumSamples() == 0);
218 ucharWrtPtr->setSample(&uc);
219 TESTING_ASSERT(ucharWrtPtr->getNumSamples() == 1);
220 }
221
222 {
223 AbcA::ScalarPropertyWriterPtr charWrtPtr =
224 props->createScalarProperty("char", AbcA::MetaData(),
225 AbcA::DataType(Alembic::Util::kInt8POD, 1), 0);
226
227 Alembic::Util::int8_t c = -20;
228 charWrtPtr->setSample(&c);
229 }
230
231 {
232 AbcA::ScalarPropertyWriterPtr ushortWrtPtr =
233 props->createScalarProperty("ushort", AbcA::MetaData(),
234 AbcA::DataType(Alembic::Util::kUint16POD, 1), 0);
235
236 Alembic::Util::uint16_t us = 60000;
237 ushortWrtPtr->setSample(&us);
238 }
239
240 {
241 AbcA::ScalarPropertyWriterPtr shortWrtPtr =
242 props->createScalarProperty("short", AbcA::MetaData(),
243 AbcA::DataType(Alembic::Util::kInt16POD, 1), 0);
244 Alembic::Util::int16_t s = -20000;
245 shortWrtPtr->setSample(&s);
246 }
247
248 {
249 AbcA::ScalarPropertyWriterPtr uintWrtPtr =
250 props->createScalarProperty("uint", AbcA::MetaData(),
251 AbcA::DataType(Alembic::Util::kUint32POD, 1), 0);
252 Alembic::Util::uint32_t ui = 1000000;
253 uintWrtPtr->setSample(&ui);
254 }
255
256 {
257 AbcA::ScalarPropertyWriterPtr intWrtPtr =
258 props->createScalarProperty("int", AbcA::MetaData(),
259 AbcA::DataType(Alembic::Util::kInt32POD, 1), 0);
260 Alembic::Util::int32_t i = -1000000;
261 intWrtPtr->setSample(&i);
262 }
263
264 {
265 AbcA::ScalarPropertyWriterPtr ui64WrtPtr =
266 props->createScalarProperty("uint64", AbcA::MetaData(),
267 AbcA::DataType(Alembic::Util::kUint64POD, 1), 0);
268 Alembic::Util::uint64_t ui = 5000000000LL;
269 ui64WrtPtr->setSample(&ui);
270 }
271
272 {
273 AbcA::ScalarPropertyWriterPtr i64WrtPtr =
274 props->createScalarProperty("i64", AbcA::MetaData(),
275 AbcA::DataType(Alembic::Util::kInt64POD, 1), 0);
276
277 Alembic::Util::int64_t i = -5000000000LL;
278 i64WrtPtr->setSample(&i);
279 }
280
281 {
282 AbcA::ScalarPropertyWriterPtr halfWrtPtr =
283 props->createScalarProperty("half", AbcA::MetaData(),
284 AbcA::DataType(Alembic::Util::kFloat16POD, 1), 0);
285
286 Alembic::Util::float16_t h = 16.0;
287 halfWrtPtr->setSample(&h);
288 }
289
290 {
291 AbcA::ScalarPropertyWriterPtr floatWrtPtr =
292 props->createScalarProperty("float", AbcA::MetaData(),
293 AbcA::DataType(Alembic::Util::kFloat32POD, 1), 0);
294
295 Alembic::Util::float32_t f = 128.0;
296 floatWrtPtr->setSample(&f);
297 }
298
299 {
300 AbcA::ScalarPropertyWriterPtr doubleWrtPtr =
301 props->createScalarProperty("double", AbcA::MetaData(),
302 AbcA::DataType(Alembic::Util::kFloat64POD, 1), 0);
303
304 Alembic::Util::float64_t d = 32768.0;
305 TESTING_ASSERT(doubleWrtPtr->getNumSamples() == 0);
306 doubleWrtPtr->setSample(&d);
307 TESTING_ASSERT(doubleWrtPtr->getNumSamples() == 1);
308 }
309
310 {
311 AbcA::ScalarPropertyWriterPtr strWrtPtr =
312 props->createScalarProperty("str", AbcA::MetaData(),
313 AbcA::DataType(Alembic::Util::kStringPOD, 1), 0);
314
315 Alembic::Util::string c = "This was a triumph!";
316 strWrtPtr->setSample(&c);
317 }
318
319 {
320 AbcA::ScalarPropertyWriterPtr wstrWrtPtr =
321 props->createScalarProperty("wstr", AbcA::MetaData(),
322 AbcA::DataType(Alembic::Util::kWstringPOD, 1), 0);
323
324 Alembic::Util::wstring c( L"Matt Lauer can suck it! \u2697" );
325 wstrWrtPtr->setSample(&c);
326 }
327
328 }
329
330 // now we read what we've written
331 {
332 A5::ReadArchive r;
333 AbcA::ArchiveReaderPtr a = r( archiveName );
334 AbcA::ObjectReaderPtr archive = a->getTop();
335 AbcA::CompoundPropertyReaderPtr parent = archive->getProperties();
336
337 TESTING_ASSERT(parent->getNumProperties() == 14);
338 for ( size_t i = 0; i < parent->getNumProperties(); ++i )
339 {
340 AbcA::BasePropertyReaderPtr bp = parent->getProperty( i );
341
342 // they are all supposed to be scalar
343 TESTING_ASSERT( bp->isScalar() );
344
345 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
346 TESTING_ASSERT( sp->getNumSamples() == 1 );
347 TESTING_ASSERT( sp->isConstant() );
348 TESTING_ASSERT( sp->getParent() == parent);
349 TESTING_ASSERT( sp->getDataType().getExtent() == 1);
350 switch (sp->getDataType().getPod())
351 {
352 case Alembic::Util::kBooleanPOD:
353 {
354 TESTING_ASSERT(sp->getName() == "bool");
355 Alembic::Util::bool_t val = false;
356 sp->getSample(0, &val);
357 TESTING_ASSERT(val == true);
358 }
359 break;
360
361 case Alembic::Util::kUint8POD:
362 {
363 TESTING_ASSERT(sp->getName() == "uchar");
364 Alembic::Util::uint8_t val = 0;
365 sp->getSample(0, &val);
366 TESTING_ASSERT(val == 200);
367 }
368 break;
369
370 case Alembic::Util::kInt8POD:
371 {
372 TESTING_ASSERT(sp->getName() == "char");
373 Alembic::Util::int8_t val = 0;
374 sp->getSample(0, &val);
375 TESTING_ASSERT(val == -20);
376 }
377 break;
378
379 case Alembic::Util::kUint16POD:
380 {
381 TESTING_ASSERT(sp->getName() == "ushort");
382 Alembic::Util::uint16_t val = 0;
383 sp->getSample(0, &val);
384 TESTING_ASSERT(val == 60000);
385 }
386 break;
387
388 case Alembic::Util::kInt16POD:
389 {
390 TESTING_ASSERT(sp->getName() == "short");
391 Alembic::Util::int16_t val = 0;
392 sp->getSample(0, &val);
393 TESTING_ASSERT(val == -20000);
394 }
395 break;
396
397 case Alembic::Util::kUint32POD:
398 {
399 TESTING_ASSERT(sp->getName() == "uint");
400 Alembic::Util::uint32_t val = 0;
401 sp->getSample(0, &val);
402 TESTING_ASSERT(val == 1000000);
403 }
404 break;
405
406 case Alembic::Util::kInt32POD:
407 {
408 TESTING_ASSERT(sp->getName() == "int");
409 Alembic::Util::int32_t val = 0;
410 sp->getSample(0, &val);
411 TESTING_ASSERT(val == -1000000);
412 }
413 break;
414
415 case Alembic::Util::kUint64POD:
416 {
417 TESTING_ASSERT(sp->getName() == "uint64");
418 Alembic::Util::uint64_t val = 0;
419 sp->getSample(0, &val);
420 TESTING_ASSERT(val == 5000000000LL);
421 }
422 break;
423
424 case Alembic::Util::kInt64POD:
425 {
426 TESTING_ASSERT(sp->getName() == "i64");
427 Alembic::Util::int64_t val = 0;
428 sp->getSample(0, &val);
429 TESTING_ASSERT(val == -5000000000LL);
430 }
431 break;
432
433 case Alembic::Util::kFloat16POD:
434 {
435 TESTING_ASSERT(sp->getName() == "half");
436 Alembic::Util::float16_t val = 0;
437 sp->getSample(0, &val);
438 TESTING_ASSERT(val == 16.0);
439 }
440 break;
441
442 case Alembic::Util::kFloat32POD:
443 {
444 TESTING_ASSERT(sp->getName() == "float");
445 Alembic::Util::float32_t val = 0;
446 sp->getSample(0, &val);
447 TESTING_ASSERT(val == 128.0);
448 }
449 break;
450
451 case Alembic::Util::kFloat64POD:
452 {
453 TESTING_ASSERT(sp->getName() == "double");
454 Alembic::Util::float64_t val = 0;
455 sp->getSample(0, &val);
456 TESTING_ASSERT(val == 32768.0);
457 }
458 break;
459
460 case Alembic::Util::kStringPOD:
461 {
462 TESTING_ASSERT(sp->getName() == "str");
463 Alembic::Util::string val;
464 sp->getSample(0, &val);
465 TESTING_ASSERT(val == "This was a triumph!");
466 }
467 break;
468
469 case Alembic::Util::kWstringPOD:
470 {
471 TESTING_ASSERT(sp->getName() == "wstr");
472 Alembic::Util::wstring val;
473 sp->getSample(0, &val);
474 TESTING_ASSERT(val == L"Matt Lauer can suck it! \u2697");
475 }
476 break;
477
478
479 default:
480 TESTING_ASSERT(false);
481 break;
482 }
483 }
484 } // end of reading
485 }
486
487 //-*****************************************************************************
488 void testRepeatedScalarData()
489 {
490 std::string archiveName = "repeatScalarData.abc";
491
492 {
493 A5::WriteArchive w;
494 AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData());
495 AbcA::ObjectWriterPtr archive = a->getTop();
496
497 AbcA::CompoundPropertyWriterPtr parent = archive->getProperties();
498
499 AbcA::ScalarPropertyWriterPtr swp =
500 parent->createScalarProperty("int32", AbcA::MetaData(),
501 AbcA::DataType(Alembic::Util::kInt32POD, 3), 0);
502
503 std::vector <Alembic::Util::uint32_t> ui(3);
504 ui[0] = 0;
505 ui[1] = 1;
506 ui[2] = 2;
507
508 std::vector <Alembic::Util::uint32_t> ui2(3);
509 ui2[0] = 41;
510 ui2[1] = 43;
511 ui2[2] = 47;
512
513 swp->setSample(&(ui.front()));
514 swp->setSample(&(ui.front()));
515 swp->setSample(&(ui2.front()));
516 swp->setSample(&(ui.front()));
517 swp->setSample(&(ui2.front()));
518 swp->setSample(&(ui2.front()));
519 swp->setSample(&(ui2.front()));
520 swp->setSample(&(ui.front()));
521 swp->setSample(&(ui.front()));
522 swp->setSample(&(ui.front()));
523
524 AbcA::ScalarPropertyWriterPtr swp2 =
525 parent->createScalarProperty("float32", AbcA::MetaData(),
526 AbcA::DataType(Alembic::Util::kFloat32POD, 1), 0);
527
528 Alembic::Util::float32_t f = 42.0;
529 Alembic::Util::float32_t f2 = -3.0;
530
531 swp2->setSample(&f);
532 swp2->setSample(&f);
533 swp2->setSample(&f);
534 swp2->setSample(&f2);
535 swp2->setSample(&f2);
536 swp2->setSample(&f2);
537
538 AbcA::ScalarPropertyWriterPtr swp3 =
539 parent->createScalarProperty("uint16", AbcA::MetaData(),
540 AbcA::DataType(Alembic::Util::kUint16POD, 1), 0);
541
542 Alembic::Util::uint16_t ui16 = 17;
543
544 swp3->setSample(&ui16);
545 swp3->setSample(&ui16);
546 swp3->setSample(&ui16);
547 swp3->setSample(&ui16);
548
549 AbcA::ScalarPropertyWriterPtr swp4 =
550 parent->createScalarProperty("str", AbcA::MetaData(),
551 AbcA::DataType(Alembic::Util::kStringPOD, 3), 0);
552
553 std::vector < Alembic::Util::string > strVec(3);
554 strVec[0] = "Please";
555 strVec[1] = "";
556 strVec[2] = "work";
557
558 std::vector < Alembic::Util::string > strVec2(3);
559 strVec2[0] = "Whats";
560 strVec2[1] = "going";
561 strVec2[2] = "on?";
562
563 swp4->setSample(&(strVec.front()));
564 swp4->setSample(&(strVec.front()));
565 swp4->setSample(&(strVec2.front()));
566 swp4->setSample(&(strVec2.front()));
567 }
568
569 {
570 A5::ReadArchive r;
571 AbcA::ArchiveReaderPtr a = r( archiveName );
572 AbcA::ObjectReaderPtr archive = a->getTop();
573
574 AbcA::CompoundPropertyReaderPtr parent = archive->getProperties();
575 TESTING_ASSERT(parent->getNumProperties() == 4);
576 for (size_t i = 0; i < parent->getNumProperties(); ++i)
577 {
578 AbcA::BasePropertyReaderPtr bp = parent->getProperty( i );
579 AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr();
580 switch (sp->getDataType().getPod())
581 {
582 case Alembic::Util::kUint16POD:
583 {
584 TESTING_ASSERT( sp->getNumSamples() == 4 );
585
586 const AbcA::TimeSamplingPtr t = sp->getTimeSampling();
587 TESTING_ASSERT( sp->isConstant() );
588
589 Alembic::Util::uint16_t us;
590
591 for ( size_t i = 0; i < sp->getNumSamples(); ++i )
592 {
593 us = 0;
594 sp->getSample( 0, &us);
595 TESTING_ASSERT(us == 17);
596 }
597 }
598 break;
599
600 case Alembic::Util::kFloat32POD:
601 {
602 TESTING_ASSERT( sp->getNumSamples() == 6 );
603 TESTING_ASSERT( sp->getDataType().getExtent() == 1);
604 TESTING_ASSERT( !sp->isConstant() );
605
606 Alembic::Util::float32_t f = 0;
607
608 // make sure we can't get a non-existant sample
609 TESTING_ASSERT_THROW(sp->getSample( 100, &f ),
610 Alembic::Util::Exception);
611
612 sp->getSample( 5, &f );
613 TESTING_ASSERT(f == -3.0);
614
615 sp->getSample( 1, &f );
616 TESTING_ASSERT(f == 42.0);
617
618 sp->getSample( 4, &f );
619 TESTING_ASSERT(f == -3.0);
620
621 sp->getSample( 0, &f );
622 TESTING_ASSERT(f == 42.0);
623
624 sp->getSample( 3, &f );
625 TESTING_ASSERT(f == -3.0);
626
627 sp->getSample( 2, &f );
628 TESTING_ASSERT(f == 42.0);
629 }
630 break;
631
632 case Alembic::Util::kInt32POD:
633 {
634 TESTING_ASSERT( sp->getNumSamples() == 10 );
635 TESTING_ASSERT( sp->getDataType().getExtent() == 3);
636 TESTING_ASSERT( !sp->isConstant() );
637
638 std::vector< Alembic::Util::uint32_t > ui(3);
639
640 // lets explicitly test each sample
641 sp->getSample( 0, &(ui.front()) );
642 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
643
644 sp->getSample( 1, &(ui.front()) );
645 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
646
647 sp->getSample( 2, &(ui.front()) );
648 TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47);
649
650 sp->getSample( 3, &(ui.front()) );
651 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
652
653 sp->getSample( 4, &(ui.front()) );
654 TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47);
655
656 sp->getSample( 5, &(ui.front()) );
657 TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47);
658
659 sp->getSample( 6, &(ui.front()) );
660 TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47);
661
662 sp->getSample( 7, &(ui.front()) );
663 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
664
665 sp->getSample( 8, &(ui.front()) );
666 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
667
668 sp->getSample( 9, &(ui.front()) );
669 TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2);
670
671 }
672 break;
673
674 case Alembic::Util::kStringPOD:
675 {
676 TESTING_ASSERT( sp->getNumSamples() == 4 );
677 TESTING_ASSERT( sp->getDataType().getExtent() == 3);
678 TESTING_ASSERT( !sp->isConstant() );
679
680 std::vector< Alembic::Util::string > val(3);
681 sp->getSample(0, &(val.front()));
682 TESTING_ASSERT( val[0] == "Please");
683 TESTING_ASSERT( val[1] == "");
684 TESTING_ASSERT( val[2] == "work");
685
686 sp->getSample(1, &(val.front()));
687 TESTING_ASSERT( val[0] == "Please");
688 TESTING_ASSERT( val[1] == "");
689 TESTING_ASSERT( val[2] == "work");
690
691 sp->getSample(2, &(val.front()));
692 TESTING_ASSERT( val[0] == "Whats");
693 TESTING_ASSERT( val[1] == "going");
694 TESTING_ASSERT( val[2] == "on?");
695
696 sp->getSample(3, &(val.front()));
697 TESTING_ASSERT( val[0] == "Whats");
698 TESTING_ASSERT( val[1] == "going");
699 TESTING_ASSERT( val[2] == "on?");
700 }
701 break;
702
703 default:
704 TESTING_ASSERT(false);
705 break;
706 }
707 } // for
708 }
709 }
710
711 AbcA::ScalarPropertyWriterPtr createObjectAndScalar(
712 AbcA::ObjectWriterPtr iParent, const std::string & iName )
713 {
714 AbcA::ObjectWriterPtr child =
715 iParent->createChild(AbcA::ObjectHeader(iName, AbcA::MetaData()));
716
717 AbcA::CompoundPropertyWriterPtr props = child->getProperties();
718
719 AbcA::ScalarPropertyWriterPtr swp =
720 props->createScalarProperty(iName, AbcA::MetaData(),
721 AbcA::DataType(Alembic::Util::kInt32POD, 1), 0);
722 return swp;
723 }
724
725 // tests a known issue where you can't write to scalar and array properties
726 // parented to the top compound if the OObject gets destroyed.
727 // http://code.google.com/p/alembic/issues/detail?id=171
728 void testPropScoping()
729 {
730 A5::WriteArchive w;
731 AbcA::ArchiveWriterPtr a = w("scopingTest.abc", AbcA::MetaData());
732 AbcA::ObjectWriterPtr archive = a->getTop();
733 AbcA::ScalarPropertyWriterPtr s = createObjectAndScalar(archive, "test");
734 Alembic::Util::int32_t val = 42;
735 s->setSample(&val);
736
737 }
738
739 int main ( int argc, char *argv[] )
740 {
741 testWeirdStringScalar();
742 testRepeatedScalarData();
743 testReadWriteScalars();
744 // testPropScoping();
745 return 0;
746 }