<commit_before>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 <NAME> 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/
#include "UnitTestFramework.h"

#include <algorithm>

namespace osgUtx
{

//////////////////////////////////////////////////////////////////////////////

TestContext::TestContext()
{
}

void TestContext::setTraceLevel(TraceLevel tl)
{
    _tout.setTraceLevel(tl);
}

TestContext::TraceLevel TestContext::getTraceLevel() const
{
    return _tout.getTraceLevel();
}

std::ostream& TestContext::tout(TraceLevel tl) const
{
    return _tout.stream(tl);
}

//////////////////////////////////////////////////////////////////////////////


TestContext::TraceStream::TraceStream(std::ostream& o, TraceLevel tl):
    _traceLevel(tl),
    _outputStreamPtr(&o),
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
    _nullStream("nul")
#else
    _nullStream("/dev/null")
#endif
{
}

TestContext::TraceStream::~TraceStream()
{
    _nullStream.close();
}

void TestContext::TraceStream::setTraceLevel(TraceLevel tl)
{
    _traceLevel = tl;
}

TestContext::TraceLevel TestContext::TraceStream::getTraceLevel() const
{
    return _traceLevel;
}

std::ostream& TestContext::TraceStream::stream(TestContext::TraceLevel tl)
{
    if(_traceLevel >= tl){
        return *_outputStreamPtr;
    }
    return _nullStream;
}

//////////////////////////////////////////////////////////////////////////////

TestGraph& TestGraph::instance()
{
    static TestGraph instance_;
    return instance_;
}

TestSuite* TestGraph::root()
{
    return root_.get();
}

TestSuite* TestGraph::suite(const std::string& path, TestSuite* tsuite, bool createIfNecessary)
{
    using namespace std;

    list<string> pathComponents;

    std::string::const_iterator it1 = path.begin();
    std::string::const_iterator it2 = it1;

    // Dissect the path into it's constituent components
    do{

        while( *it2 != '.' && it2 != path.end() ) ++it2;

        // Consider a check for "" empty strings?
        pathComponents.push_back( std::string(it1,it2) );

        if( it2 != path.end()) ++it2;

        it1 = it2;

    }while( it2 != path.end());

    return suite(pathComponents.begin(), pathComponents.end(),
            tsuite, createIfNecessary);

}

TestSuite* TestGraph::suite(
        std::list<std::string>::iterator it,
        std::list<std::string>::iterator end,
        TestSuite* tsuite, bool createIfNecessary)
{
    using namespace std;

    if( ! tsuite) tsuite = root();

    // Make sure these tie up
    if(*it != tsuite->name()) return 0;

    ++it;
    if(it == end) return tsuite;
<commit_msg>From <NAME>, "Visual Studio 2005 triggered a small glitch in UnittestFramework.cpp<commit_after>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 <NAME> 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/
#include "UnitTestFramework.h"

#include <algorithm>

namespace osgUtx
{

//////////////////////////////////////////////////////////////////////////////

TestContext::TestContext()
{
}

void TestContext::setTraceLevel(TraceLevel tl)
{
    _tout.setTraceLevel(tl);
}

TestContext::TraceLevel TestContext::getTraceLevel() const
{
    return _tout.getTraceLevel();
}

std::ostream& TestContext::tout(TraceLevel tl) const
{
    return _tout.stream(tl);
}

//////////////////////////////////////////////////////////////////////////////


TestContext::TraceStream::TraceStream(std::ostream& o, TraceLevel tl):
    _traceLevel(tl),
    _outputStreamPtr(&o),
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
    _nullStream("nul")
#else
    _nullStream("/dev/null")
#endif
{
}

TestContext::TraceStream::~TraceStream()
{
    _nullStream.close();
}

void TestContext::TraceStream::setTraceLevel(TraceLevel tl)
{
    _traceLevel = tl;
}

TestContext::TraceLevel TestContext::TraceStream::getTraceLevel() const
{
    return _traceLevel;
}

std::ostream& TestContext::TraceStream::stream(TestContext::TraceLevel tl)
{
    if(_traceLevel >= tl){
        return *_outputStreamPtr;
    }
    return _nullStream;
}

//////////////////////////////////////////////////////////////////////////////

TestGraph& TestGraph::instance()
{
    static TestGraph instance_;
    return instance_;
}

TestSuite* TestGraph::root()
{
    return root_.get();
}

TestSuite* TestGraph::suite(const std::string& path, TestSuite* tsuite, bool createIfNecessary)
{
    using namespace std;

    list<string> pathComponents;

    std::string::const_iterator it1 = path.begin();
    std::string::const_iterator it2 = it1;

    // Dissect the path into it's constituent components
    do{

        while( it2 != path.end() && *it2 != '.' ) ++it2;

        // Consider a check for "" empty strings?
        pathComponents.push_back( std::string(it1,it2) );

        if( it2 != path.end()) ++it2;

        it1 = it2;

    }while( it2 != path.end());

    return suite(pathComponents.begin(), pathComponents.end(),
            tsuite, createIfNecessary);

}

TestSuite* TestGraph::suite(
        std::list<std::string>::iterator it,
        std::list<std::string>::iterator end,
        TestSuite* tsuite, bool createIfNecessary)
{
    using namespace std;

    if( ! tsuite) tsuite = root();

    // Make sure these tie up
    if(*it != tsuite->name()) return 0;

    ++it;
    if(it == end) return tsuite;

{'fraction_non_alphanumeric': 0.19142902158500077, 'fraction_numerical': 0.009453285016543248, 'mean_word_length': 2.7830750893921334, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5820557', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1830, 'n_words': 494}