X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Ftest_binobj.cxx;h=00b697906c1cabbe5c2fb22263fc97b8123b74ee;hb=201cb61f842ef50a19438e3872ba22e588fa1afc;hp=20c7ad338e233b441a9585711490186cbac0d895;hpb=bc9b3f6ff1fcc5caa67c07ad99f971c0faacf91a;p=simgear.git diff --git a/simgear/io/test_binobj.cxx b/simgear/io/test_binobj.cxx index 20c7ad33..00b69790 100644 --- a/simgear/io/test_binobj.cxx +++ b/simgear/io/test_binobj.cxx @@ -9,6 +9,10 @@ #include #include +#if defined _MSC_VER || defined _WIN32_WINNT +# define random rand +#endif + #include #include "sg_binobj.hxx" @@ -246,12 +250,88 @@ void test_big() compareTris(basic, rd); } +void test_some_objects() +{ + SGBinObject basic; + SGPath path(simgear::Dir::current().file("some_objects.btg.gz")); + + SGVec3d center(1, 2, 3); + basic.set_gbs_center(center); + basic.set_gbs_radius(12345); + + std::vector points; + generate_points(10000, points); + std::vector normals; + generate_normals(1024, normals); + std::vector texCoords; + generate_tcs(20000, texCoords); + + basic.set_wgs84_nodes(points); + basic.set_normals(normals); + basic.set_texcoords(texCoords); + + generate_tris(basic, 30000); // a number smaller than 2^15! + + bool ok = basic.write_bin_file(path); + VERIFY( ok ); + + SGBinObject rd; + ok = rd.read_bin(path.str()) ; + VERIFY( ok); + COMPARE(rd.get_version(), 7); // since we have less than 2^15 tris + COMPARE(rd.get_wgs84_nodes().size(), points.size()); + COMPARE(rd.get_texcoords().size(), texCoords.size()); + + comparePoints(rd, points); + compareTexCoords(rd, texCoords); + compareTris(basic, rd); +} + +void test_many_objects() +{ + SGBinObject basic; + SGPath path(simgear::Dir::current().file("many_objects.btg.gz")); + + SGVec3d center(1, 2, 3); + basic.set_gbs_center(center); + basic.set_gbs_radius(12345); + + std::vector points; + generate_points(10000, points); + std::vector normals; + generate_normals(1024, normals); + std::vector texCoords; + generate_tcs(20000, texCoords); + + basic.set_wgs84_nodes(points); + basic.set_normals(normals); + basic.set_texcoords(texCoords); + + generate_tris(basic, 200000); + + bool ok = basic.write_bin_file(path); + VERIFY( ok ); + + SGBinObject rd; + ok = rd.read_bin(path.str()) ; + VERIFY( ok); + COMPARE(rd.get_version(), 10); // should be version 10 since indices are > 2^16 + COMPARE(rd.get_wgs84_nodes().size(), points.size()); + COMPARE(rd.get_texcoords().size(), texCoords.size()); + + comparePoints(rd, points); + compareTexCoords(rd, texCoords); + compareTris(basic, rd); +} + int main(int argc, char* argv[]) { test_empty(); test_basic(); test_many_tcs(); test_big(); + test_some_objects(); + test_many_objects(); return 0; }