PageRenderTime 54ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/tests/stringize_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 104 lines | 53 code | 10 blank | 41 comment | 0 complexity | 2cfaf1b420f60ad342d65ee400374c28 MD5 | raw file
  1/**
  2 * @file   stringize_test.cpp
  3 * @author Nat Goodspeed
  4 * @date   2008-09-12
  5 * @brief  Test of stringize.h
  6 * 
  7 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29/*==========================================================================*|
 30#if LL_WINDOWS
 31#pragma warning (disable : 4675) // "resolved by ADL" -- just as I want!
 32#endif
 33|*==========================================================================*/
 34
 35// STL headers
 36#include <iomanip>
 37
 38// Precompiled header
 39#include "linden_common.h"
 40
 41// associated header
 42#include "../stringize.h"
 43
 44// std headers
 45// external library headers
 46// other Linden headers
 47#include "../llsd.h"
 48
 49#include "../test/lltut.h"
 50
 51namespace tut
 52{
 53    struct stringize_data
 54    {
 55        stringize_data():
 56            c('c'),
 57            s(17),
 58            i(34),
 59            l(68),
 60            f(3.14159265358979f),
 61            d(3.14159265358979),
 62            // Including a space differentiates this from
 63            // boost::lexical_cast<std::string>, which doesn't handle embedded
 64            // spaces so well.
 65            abc("abc def")
 66        {
 67            llsd["i"]   = i;
 68            llsd["d"]   = d;
 69            llsd["abc"] = abc;
 70        }
 71
 72        char        c;
 73        short       s;
 74        int         i;
 75        long        l;
 76        float       f;
 77        double      d;
 78        std::string abc;
 79        LLSD        llsd;
 80    };
 81    typedef test_group<stringize_data> stringize_group;
 82    typedef stringize_group::object stringize_object;
 83    tut::stringize_group strzgrp("stringize_h");
 84
 85    template<> template<>
 86    void stringize_object::test<1>()
 87    {
 88        ensure_equals(stringize(c),    "c");
 89        ensure_equals(stringize(s),    "17");
 90        ensure_equals(stringize(i),    "34");
 91        ensure_equals(stringize(l),    "68");
 92        ensure_equals(stringize(f),    "3.14159");
 93        ensure_equals(stringize(d),    "3.14159");
 94        ensure_equals(stringize(abc),  "abc def");
 95        ensure_equals(stringize(llsd), "{'abc':'abc def','d':r3.14159,'i':i34}");
 96    }
 97
 98    template<> template<>
 99    void stringize_object::test<2>()
100    {
101        ensure_equals(STRINGIZE("c is " << c), "c is c");
102        ensure_equals(STRINGIZE(std::setprecision(4) << d), "3.142");
103    }
104} // namespace tut