Hi,

I'm using CxxTest 3.10.1 to unit-test my code.  I wrote an extension to 
correctly handle osg::Vec3 data, which works fine on MSVC, but won't compile 
using GCC 4.3.3.

The extension consists of two parts - a ValueTraits-implementation to print 
osg::Vec3 data in readable form, and a delta-function to check if two osg::Vec3 
are almost equal.

The extension:

Code:

#include <osg/Vec3>
#include <osg/io_utils>

namespace CxxTest {
    CXXTEST_TEMPLATE_INSTANTIATION
    class ValueTraits<osg::Vec3> {
        std::string s;
      public:
        ValueTraits(const osg::Vec3& v) {
            std::ostringstream oss;
            oss << "osg::Vec3(" << v << ")";
            s = oss.str();
        }
        const char* asString() const { return s.c_str(); }
    };

    template <class D>
    bool delta (osg::Vec3 x, osg::Vec3 y, D d) {
        return ((y.x() >= x.x() - d) && y.x() <= x.x() + d) &&
                (y.y() >= x.y() - d) && y.y() <= x.y() + d) &&
                (y.z() >= x.z() - d) && y.z() <= x.z() + d));
    }
}




I use it in a test like this:

Code:

void test_vec3 {
    osg::Vec3 a(1.0, 1.0, 1.0);
    osg::Vec3 b(1.01, 1.01, 1.01);

    TS_ASSERT_DELTA(a, b, 0.001);   // Fails
    TS_ASSERT_DELTA(a, b, 0.1);     // Passes
}




When compiling with gcc it seems like my delta-function is not found or used,
the compiler tries to use the generic templated "delta(X x, Y y, D d)", which
tries to test for "y >= x - d && y <= x + d".

Compiler-output:


Code:

/home/docdrum/dev/OsgProjectTests/tests/cpptests/lib/cxxtest/cxxtest/TestSuite.h:
 In function »bool CxxTest::delta(X, Y, D) [with X = osg::Vec3f, Y = 
osg::Vec3f, D = double]«:
/home/docdrum/dev/OsgProjectTests/tests/cpptests/lib/cxxtest/cxxtest/TestSuite.h:172:
   instantiated from »void CxxTest::doAssertDelta(const char*, unsigned int, 
const char*, X, const char*, Y, const char*, D, const char*) [with X = 
osg::Vec3f, Y = osg::Vec3f, D = double]«
/home/docdrum/dev/OsgProjectTests/tests/cpptests/unit/UnitTest.h:122:   
instantiated from here
/home/docdrum/dev/OsgProjectTests/tests/cpptests/lib/cxxtest/cxxtest/TestSuite.h:162:
 Fehler: no match für »operator+« in »x + d«
/usr/include/osg/Vec3f:135: Anmerkung: Kandidaten sind: const osg::Vec3f 
osg::Vec3f::operator+(const osg::Vec3f&) const
/home/docdrum/dev/OsgProjectTests/tests/cpptests/lib/cxxtest/cxxtest/TestSuite.h:162:
 Fehler: no match für »operator-« in »x - d«
/usr/include/osg/Vec3f:152: Anmerkung: Kandidaten sind: const osg::Vec3f 
osg::Vec3f::operator-(const osg::Vec3f&) const
/usr/include/osg/Vec3f:167: Anmerkung:                  const osg::Vec3f 
osg::Vec3f::operator-() const
make[2]: *** [tests/cpptests/unit/CMakeFiles/UnitTest.dir/UnitTest.cpp.o] 
Fehler 1
make[1]: *** [tests/cpptests/unit/CMakeFiles/UnitTest.dir/all] Fehler 2
make: *** [all] Fehler 2




I tried using all combinations of osg::Vec3f instead of osg::Vec3, using 
const-references, float- and double-parameters for d instead of templating...

Any ideas how I can make this work on GCC?

Thank you!

Cheers,
Colin
[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45407#45407





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to