Show
Ignore:
Timestamp:
12/24/06 07:27:43 (2 years ago)
Author:
cneumann
Message:

Added copyright headers,
wrapped test contents in SUITEs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoStatsAttachmentTest.cpp

    r448 r457  
     1/*---------------------------------------------------------------------------*\ 
     2 *                                OpenSG                                     * 
     3 *                                                                           * 
     4 *                                                                           * 
     5 *               Copyright (C) 2000-2006 by the OpenSG Forum                 * 
     6 *                                                                           * 
     7 *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          * 
     8 *                                                                           * 
     9\*---------------------------------------------------------------------------*/ 
     10/*---------------------------------------------------------------------------*\ 
     11 *                                License                                    * 
     12 *                                                                           * 
     13 * This library is free software; you can redistribute it and/or modify it   * 
     14 * under the terms of the GNU Library General Public License as published    * 
     15 * by the Free Software Foundation, version 2.                               * 
     16 *                                                                           * 
     17 * This library is distributed in the hope that it will be useful, but       * 
     18 * WITHOUT ANY WARRANTY; without even the implied warranty of                * 
     19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         * 
     20 * Library General Public License for more details.                          * 
     21 *                                                                           * 
     22 * You should have received a copy of the GNU Library General Public         * 
     23 * License along with this library; if not, write to the Free Software       * 
     24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 * 
     25 *                                                                           * 
     26\*---------------------------------------------------------------------------*/ 
     27/*---------------------------------------------------------------------------*\ 
     28 *                                Changes                                    * 
     29 *                                                                           * 
     30 *                                                                           * 
     31 *                                                                           * 
     32 *                                                                           * 
     33 *                                                                           * 
     34 *                                                                           * 
     35\*---------------------------------------------------------------------------*/ 
    136 
    237#include <UnitTest++.h> 
     
    1853    { 
    1954        GeoBuilder b; 
    20          
     55 
    2156        root = makeNodeFor(Group::create()); 
    2257        geos0Node = makeNodeFor(Group::create()); 
    23          
     58 
    2459        root->addChild(geos0Node); 
    25             
     60 
    2661        // Test geometry 0: a single triangle 
    2762        b.begin(GL_TRIANGLES); 
     
    3065        b.vertex(Vec3f(0,1,0)); 
    3166        b.end(); 
    32          
     67 
    3368        geos[0]                         = b.getGeometry(); 
    3469        geoVertices[0]                  = 3; 
     
    3873        geoProcessedAttributeBytes[0]   = 3*sizeof(Vec3f); 
    3974        geoStoredAttributeBytes[0]      = 3*sizeof(Vec3f); 
    40              
     75 
    4176        nodes[0] = makeNodeFor(geos[0]); 
    4277        geos0Node->addChild(nodes[0]); // Add a second level 
    43          
     78 
    4479        // Test geometry 1: a triangle and a quad 
    4580        b.reset(); 
     
    5388        b.vertex(Vec3f(3,2,0)); 
    5489        b.vertex(Vec3f(2,2,0)); 
    55          
     90 
    5691        b.tri(0); 
    5792        b.quad(3); 
    58          
     93 
    5994        geos[1]                         = b.getGeometry(); 
    6095        geoVertices[1]                  = 7; 
     
    6499        geoProcessedAttributeBytes[1]   = 7*sizeof(Vec3f); 
    65100        geoStoredAttributeBytes[1]      = 7*sizeof(Vec3f); 
    66              
     101 
    67102        nodes[1] = makeNodeFor(geos[1]); 
    68103        root->addChild(nodes[1]); 
    69          
     104 
    70105        // Test geometry 2: Sharing some vertices 
    71106        b.reset(); 
     
    77112        b.vertex(Vec3f(2,1,0)); 
    78113        b.vertex(Vec3f(3,0,0)); 
    79          
     114 
    80115        b.tri(0); 
    81116        b.quad(1); 
    82          
     117 
    83118        geos[2]                         = b.getGeometry(); 
    84119        geoVertices[2]                  = 7; 
     
    88123        geoProcessedAttributeBytes[2]   = 7*sizeof(Vec3f); 
    89124        geoStoredAttributeBytes[2]      = 5*sizeof(Vec3f); 
    90              
     125 
    91126        nodes[2] = makeNodeFor(geos[2]); 
    92127        root->addChild(nodes[2]); 
    93          
     128 
    94129        commitChanges(); 
    95          
    96         sumVertices = sumPoints = sumLines = sumTriangles =  
     130 
     131        sumVertices = sumPoints = sumLines = sumTriangles = 
    97132            sumProcessedAttributeBytes = sumStoredAttributeBytes = 0; 
    98              
     133 
    99134        for(UInt32 i = 0; i < nGeos; ++i) 
    100135        { 
     
    105140            sumProcessedAttributeBytes += geoProcessedAttributeBytes[i]; 
    106141            sumStoredAttributeBytes += geoStoredAttributeBytes[i]; 
    107              
     142 
    108143        } 
    109144    } 
    110      
     145 
    111146    ~GSAFixture() 
    112147    { 
    113148    } 
    114      
     149 
    115150    // Number of test geometries 
    116151    static const int nGeos = 3; 
    117      
     152 
    118153    // Test Geometries, see above 
    119154    RefPtr<GeometryPtr> geos[nGeos]; 
    120      
     155 
    121156    // Stats Data for test geometries 
    122157    UInt32 geoVertices[nGeos]; 
     
    126161    UInt32 geoProcessedAttributeBytes[nGeos]; 
    127162    UInt32 geoStoredAttributeBytes[nGeos]; 
    128      
     163 
    129164    // Summed stats data 
    130165    UInt32 sumVertices; 
     
    134169    UInt32 sumProcessedAttributeBytes; 
    135170    UInt32 sumStoredAttributeBytes; 
    136      
     171 
    137172    // Nodes for tree test 
    138173    RefPtr<NodePtr> nodes[nGeos]; 
     
    148183        RefPtr<GeoStatsAttachmentPtr> st; 
    149184        st = GeoStatsAttachment::calcStatic(g); 
    150          
     185 
    151186        CHECK_EQUAL(geoVertices[i], st->getVertices()); 
    152187        CHECK_EQUAL(geoPoints[i], st->getPoints()); 
     
    161196{ 
    162197    RefPtr<GeoStatsAttachmentPtr> sum; 
    163      
     198 
    164199    sum = GeoStatsAttachment::create(); 
    165      
     200 
    166201    UInt32 v = 0,p = 0,l = 0,t = 0,pb = 0,sb = 0; 
    167      
     202 
    168203    for(int i = 0; i < nGeos; ++i) 
    169204    { 
     
    173208        //sum += st; 
    174209        sum->operator+=(st); 
    175          
     210 
    176211        v  += st->getVertices(); 
    177212        p  += st->getPoints(); 
     
    181216        sb += st->getStoredAttributeBytes(); 
    182217    } 
    183      
     218 
    184219    CHECK_EQUAL(v, sum->getVertices()); 
    185220    CHECK_EQUAL(p, sum->getPoints()); 
     
    187222    CHECK_EQUAL(t, sum->getTriangles()); 
    188223    CHECK_EQUAL(pb, sum->getProcessedAttributeBytes()); 
    189     CHECK_EQUAL(sb, sum->getStoredAttributeBytes());   
    190      
     224    CHECK_EQUAL(sb, sum->getStoredAttributeBytes()); 
     225 
    191226    //sum -= sum; 
    192227    sum->operator-=(sum); 
     
    196231    CHECK_EQUAL(sum->getTriangles(), 0); 
    197232    CHECK_EQUAL(sum->getProcessedAttributeBytes(), 0); 
    198     CHECK_EQUAL(sum->getStoredAttributeBytes(), 0);   
    199      
     233    CHECK_EQUAL(sum->getStoredAttributeBytes(), 0); 
     234 
    200235} 
    201236 
     
    203238{ 
    204239    GeoStatsAttachment::addTo(geos[0]); 
    205      
    206     RefPtr<GeoStatsAttachmentPtr> st; 
    207     st = GeoStatsAttachment::get(geos[0]); 
    208      
     240 
     241    RefPtr<GeoStatsAttachmentPtr> st; 
     242    st = GeoStatsAttachment::get(geos[0]); 
     243 
    209244    CHECK(st != NullFC); 
    210245 
     
    222257{ 
    223258    GeoStatsAttachmentPtr st; 
    224      
     259 
    225260    st = GeoStatsAttachment::get(geos[0]); 
    226261    CHECK(st == NullFC); 
    227      
     262 
    228263    GeoStatsAttachment::addTo(geos[0]); 
    229      
    230     st = GeoStatsAttachment::get(geos[0]); 
    231       
     264 
     265    st = GeoStatsAttachment::get(geos[0]); 
     266 
    232267    CHECK(st != NullFC); 
    233268} 
     
    236271{ 
    237272    GeoStatsAttachment::addTo(geos[0]); 
    238      
    239     RefPtr<GeoStatsAttachmentPtr> st; 
    240     st = GeoStatsAttachment::get(geos[0]); 
    241  
    242     CHECK(st != NullFC); 
    243      
     273 
     274    RefPtr<GeoStatsAttachmentPtr> st; 
     275    st = GeoStatsAttachment::get(geos[0]); 
     276 
     277    CHECK(st != NullFC); 
     278 
    244279    st->attachTo(geos[1]); 
    245280 
    246281    st = GeoStatsAttachment::get(geos[0]); 
    247282 
    248     CHECK(st == NullFC);   // Removed from old one?  
     283    CHECK(st == NullFC);   // Removed from old one? 
    249284 
    250285    st = GeoStatsAttachment::get(geos[1]); 
    251286 
    252     CHECK(st != NullFC);    // Attached to new one?  
    253  
    254     CHECK_EQUAL(st->getValid(), false); // Should be invalid now  
    255      
    256     st->validate(); 
    257  
    258     CHECK_EQUAL(st->getValid(), true); // Should be valid now  
     287    CHECK(st != NullFC);    // Attached to new one? 
     288 
     289    CHECK_EQUAL(st->getValid(), false); // Should be invalid now 
     290 
     291    st->validate(); 
     292 
     293    CHECK_EQUAL(st->getValid(), true); // Should be valid now 
    259294 
    260295    CHECK_EQUAL(geoVertices[1], st->getVertices()); 
     
    269304{ 
    270305    GeoStatsAttachment::addTo(nodes[0]); 
    271      
     306 
    272307    RefPtr<GeoStatsAttachmentPtr> st; 
    273308    st = GeoStatsAttachment::get(nodes[0]); 
     
    287322// Add to multiple tree levels 
    288323TEST_FIXTURE(GSAFixture, AddToGroupNodes) 
    289 {     
     324{ 
    290325    GeoStatsAttachment::addTo(geos0Node); 
    291326    GeoStatsAttachment::addTo(nodes[0]); 
    292      
     327 
    293328    RefPtr<GeoStatsAttachmentPtr> st; 
    294329    st = GeoStatsAttachment::get(geos0Node); 
     
    308343// Add to one tree level, should update all lower levels automatically 
    309344TEST_FIXTURE(GSAFixture, AddToGroupNode) 
    310 {     
     345{ 
    311346    GeoStatsAttachment::addTo(geos0Node); 
    312      
     347 
    313348    RefPtr<GeoStatsAttachmentPtr> st; 
    314349    st = GeoStatsAttachment::get(geos0Node); 
     
    328363// Automatic Invalidation 
    329364TEST_FIXTURE(GSAFixture, AutoInvalidateGeometryOnChange) 
    330 {     
     365{ 
    331366    GeoStatsAttachment::addTo(geos[0]); 
    332      
    333     RefPtr<GeoStatsAttachmentPtr> st; 
    334     st = GeoStatsAttachment::get(geos[0]); 
    335  
    336     CHECK(st != NullFC); 
    337  
    338     st->validate(); 
    339      
     367 
     368    RefPtr<GeoStatsAttachmentPtr> st; 
     369    st = GeoStatsAttachment::get(geos[0]); 
     370 
     371    CHECK(st != NullFC); 
     372 
     373    st->validate(); 
     374 
    340375    commitChanges(); 
    341376 
     
    346381    CHECK_EQUAL(geoProcessedAttributeBytes[0], st->getProcessedAttributeBytes()); 
    347382    CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 
    348      
     383 
    349384    geos[0]->getTypes()->push_back(GL_LINE_STRIP); 
    350385    geos[0]->getLengths()->push_back(3); 
     
    352387    geos[0]->getIndex(0)->push_back(1); 
    353388    geos[0]->getIndex(0)->push_back(2); 
    354      
     389 
    355390    commitChanges(); 
    356      
     391 
    357392    CHECK_EQUAL(st->getValid(), false); 
    358393 
    359394    st->validate(); 
    360      
     395 
    361396    CHECK_EQUAL(st->getValid(), true); 
    362      
     397 
    363398    CHECK_EQUAL(geoVertices[0] + 3, st->getVertices()); 
    364399    CHECK_EQUAL(geoPoints[0], st->getPoints()); 
    365400    CHECK_EQUAL(geoLines[0] + 2, st->getLines()); 
    366401    CHECK_EQUAL(geoTriangles[0], st->getTriangles()); 
    367     CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3,  
     402    CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 
    368403                    st->getProcessedAttributeBytes()); 
    369     CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes());       
     404    CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 
    370405} 
    371406 
    372407// Automatic Invalidation 
    373408TEST_FIXTURE(GSAFixture, AutoInvalidateNodeOnChange) 
    374 {     
     409{ 
    375410    GeoStatsAttachment::addTo(nodes[0]); 
    376      
     411 
    377412    RefPtr<GeoStatsAttachmentPtr> st; 
    378413    st = GeoStatsAttachment::get(nodes[0]); 
     
    381416 
    382417    st->validate(); 
    383      
     418 
    384419    commitChanges(); 
    385420 
     
    390425    CHECK_EQUAL(geoProcessedAttributeBytes[0], st->getProcessedAttributeBytes()); 
    391426    CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 
    392      
     427 
    393428    geos[0]->getTypes()->push_back(GL_LINE_STRIP); 
    394429    geos[0]->getLengths()->push_back(3); 
     
    396431    geos[0]->getIndex(0)->push_back(1); 
    397432    geos[0]->getIndex(0)->push_back(2); 
    398      
     433 
    399434    commitChanges(); 
    400      
     435 
    401436    CHECK_EQUAL(st->getValid(), false); 
    402437 
    403438    st->validate(); 
    404      
     439 
    405440    CHECK_EQUAL(st->getValid(), true); 
    406      
     441 
    407442    CHECK_EQUAL(geoVertices[0] + 3, st->getVertices()); 
    408443    CHECK_EQUAL(geoPoints[0], st->getPoints()); 
    409444    CHECK_EQUAL(geoLines[0] + 2, st->getLines()); 
    410445    CHECK_EQUAL(geoTriangles[0], st->getTriangles()); 
    411     CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3,  
     446    CHECK_EQUAL(geoProcessedAttributeBytes[0] + sizeof(Vec3f) * 3, 
    412447                    st->getProcessedAttributeBytes()); 
    413     CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes());       
     448    CHECK_EQUAL(geoStoredAttributeBytes[0], st->getStoredAttributeBytes()); 
    414449} 
    415450 
    416451// Hierarchical Invalidation 
    417452TEST_FIXTURE(GSAFixture, AutoInvalidateHierarchy) 
    418 {     
     453{ 
    419454    RefPtr<GeoStatsAttachmentPtr> st; 
    420455    st = GeoStatsAttachment::get(root); 
     
    426461 
    427462    CHECK(st != NullFC); 
    428      
     463 
    429464    st->validate(); 
    430465 
     
    435470    CHECK_EQUAL(sumProcessedAttributeBytes, st->getProcessedAttributeBytes()); 
    436471    CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes()); 
    437      
     472 
    438473    geos[0]->getTypes()->push_back(GL_LINE_STRIP); 
    439474    geos[0]->getLengths()->push_back(3); 
     
    441476    geos[0]->getIndex(0)->push_back(1); 
    442477    geos[0]->getIndex(0)->push_back(2); 
    443      
     478 
    444479    commitChanges(); 
    445      
     480 
    446481    CHECK_EQUAL(false, st->getValid()); 
    447482 
    448483    st->validate(); 
    449      
     484 
    450485    CHECK_EQUAL(true, st->getValid()); 
    451      
     486 
    452487    CHECK_EQUAL(sumVertices + 3, st->getVertices()); 
    453488    CHECK_EQUAL(sumPoints, st->getPoints()); 
    454489    CHECK_EQUAL(sumLines + 2, st->getLines()); 
    455490    CHECK_EQUAL(sumTriangles, st->getTriangles()); 
    456     CHECK_EQUAL(sumProcessedAttributeBytes + sizeof(Vec3f) * 3,  
     491    CHECK_EQUAL(sumProcessedAttributeBytes + sizeof(Vec3f) * 3, 
    457492                    st->getProcessedAttributeBytes()); 
    458     CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes());       
    459 } 
    460  
    461 } 
     493    CHECK_EQUAL(sumStoredAttributeBytes, st->getStoredAttributeBytes()); 
     494} 
     495 
     496} // SUITE