Skip to content

Commit

Permalink
Add 'operator<<' for tinyusdz::Interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Jun 7, 2024
1 parent 2c43e48 commit 3666b55
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/pprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ std::string pquote(const Path &p) {

namespace std {

std::ostream &operator<<(std::ostream &ofs, tinyusdz::Visibility v) {
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Visibility v) {
ofs << to_string(v);
return ofs;
}

std::ostream &operator<<(std::ostream &ofs, tinyusdz::Extent v) {
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Extent v) {
ofs << to_string(v);

return ofs;
}

std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Interpolation v) {
ofs << to_string(v);

return ofs;
Expand Down
5 changes: 3 additions & 2 deletions src/pprinter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ std::string print_collection(const Collection *coll, const uint32_t indent);

namespace std {

std::ostream &operator<<(std::ostream &ofs, tinyusdz::Visibility v);
std::ostream &operator<<(std::ostream &ofs, tinyusdz::Extent v);
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Visibility v);
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Extent v);
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Interpolation v);
std::ostream &operator<<(std::ostream &ofs, const tinyusdz::Layer &layer);

} // namespace std
1 change: 1 addition & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(TEST_SOURCES
unit-prim-types.cc
unit-primvar.cc
unit-pathutil.cc
unit-pprint.cc
unit-strutil.cc
unit-value-types.cc
unit-xform.cc
Expand Down
1 change: 1 addition & 0 deletions tests/unit/unit-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "unit-ioutil.h"
#include "unit-strutil.h"
#include "unit-timesamples.h"
#include "unit-pprint.h"

#if defined(TINYUSDZ_WITH_PXR_COMPAT_API)
#include "unit-pxr-compat-api.h"
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/unit-pprint.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifdef _MSC_VER
#define NOMINMAX
#endif

#define TEST_NO_MAIN
#include "acutest.h"

#include "unit-pprint.h"
#include "prim-types.hh"
#include "value-types.hh"
#include "value-pprint.hh"
#include "pprinter.hh"

using namespace tinyusdz;

void value_type_pprint_test(void) {

{
std::stringstream ss;
tinyusdz::Interpolation interp = tinyusdz::Interpolation::Vertex;
ss << interp;
TEST_CHECK(ss.str() == "vertex");
}

{
value::normal3f v{1.0f, 2.0f, 3.f};
std::string s = to_string(v);
TEST_CHECK(s == "(1, 2, 3)");
}
}

3 changes: 3 additions & 0 deletions tests/unit/unit-pprint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void value_type_pprint_test(void);
7 changes: 0 additions & 7 deletions tests/unit/unit-value-types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "unit-value-types.h"
#include "value-types.hh"
#include "value-pprint.hh"

using namespace tinyusdz;

Expand All @@ -28,11 +27,5 @@ void value_types_test(void) {

TEST_CHECK(!value::TryGetTypeName(value::TYPE_ID_ALL));

// pprint test
{
value::normal3f v{1.0f, 2.0f, 3.f};
std::string s = to_string(v);
TEST_CHECK(s == "(1, 2, 3)");
}
}

0 comments on commit 3666b55

Please sign in to comment.