| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include "gtest/gtest.h" |
| 36 |
#include "stk_util/diag/String.hpp" |
| 37 |
#include "stk_util/diag/Resource2.h" |
| 38 |
#include <string> |
| 39 |
|
| 40 |
TEST(Resource2, invalid_name) |
| 41 |
{ |
| 42 |
sierra::String regionName("regionResource"); |
| 43 |
sierra::Rsrc2::ResourceRoot regionResource(regionName); |
| 44 |
EXPECT_ANY_THROW(regionResource.create("foo.bar", nullptr)); |
| 45 |
} |
| 46 |
|
| 47 |
TEST(Resource2, construct_list_and_find) |
| 48 |
{ |
| 49 |
sierra::String parentName("parentResource"); |
| 50 |
sierra::Rsrc2::ResourceRoot resourceRoot(parentName); |
| 51 |
sierra::Rsrc2::ResourceList resourceList; |
| 52 |
constexpr int N = 5; |
| 53 |
for(int i=0; i<N; ++i) { |
| 54 |
sierra::String name("ABC_"+std::to_string(i)); |
| 55 |
resourceList.insert(resourceRoot.create_value<int>(name, i)); |
| 56 |
} |
| 57 |
|
| 58 |
EXPECT_EQ(static_cast<size_t>(N), resourceList.size()); |
| 59 |
|
| 60 |
sierra::String name("ABC_2"); |
| 61 |
sierra::Rsrc2::ResourceList::iterator iter = resourceList.find(name); |
| 62 |
EXPECT_TRUE(iter != resourceList.end()); |
| 63 |
EXPECT_EQ(iter->value<int>(), 2); |
| 64 |
} |
| 65 |
|
| 66 |
TEST(Resource2, match) |
| 67 |
{ |
| 68 |
sierra::String parentName("parentResource"); |
| 69 |
sierra::Rsrc2::ResourceRoot resourceRoot(parentName); |
| 70 |
sierra::Rsrc2::ResourceList resourceList; |
| 71 |
constexpr int N = 5; |
| 72 |
for(int i=0; i<N; ++i) { |
| 73 |
sierra::String name("ABC_"+std::to_string(i)); |
| 74 |
resourceList.insert(resourceRoot.create_value<int>(name, i)); |
| 75 |
} |
| 76 |
|
| 77 |
EXPECT_EQ(static_cast<size_t>(N), resourceList.size()); |
| 78 |
|
| 79 |
sierra::String name("ABC_2"); |
| 80 |
sierra::Rsrc2::ResourceList matchList; |
| 81 |
resourceList.match(name, matchList); |
| 82 |
|
| 83 |
EXPECT_EQ(1u, matchList.size()); |
| 84 |
EXPECT_EQ(matchList.front().value<int>(), 2); |
| 85 |
} |
| 86 |
|
| 87 |
TEST(Resource2, match_recursive) |
| 88 |
{ |
| 89 |
sierra::String regionName("regionResource"); |
| 90 |
sierra::Rsrc2::ResourceRoot regionResource(regionName); |
| 91 |
constexpr int N = 5; |
| 92 |
for(int i=0; i<N; ++i) { |
| 93 |
sierra::String name("ABC_"+std::to_string(i)); |
| 94 |
regionResource.create_value<int>(name, i); |
| 95 |
} |
| 96 |
|
| 97 |
sierra::String procedureName("procedureResource"); |
| 98 |
sierra::Rsrc2::ResourceRoot procedureResource(procedureName); |
| 99 |
for(int i=0; i<N; ++i) { |
| 100 |
sierra::String name("DEF_"+std::to_string(i)); |
| 101 |
procedureResource.create_value<int>(name, i); |
| 102 |
} |
| 103 |
|
| 104 |
sierra::Rsrc2::ResourceList resourceList; |
| 105 |
resourceList.insert(procedureResource); |
| 106 |
resourceList.insert(regionResource); |
| 107 |
EXPECT_EQ(2u, resourceList.size()); |
| 108 |
|
| 109 |
{ |
| 110 |
sierra::String name("ABC_2"); |
| 111 |
sierra::Rsrc2::ResourceList matchList; |
| 112 |
resourceList.match(name, matchList); |
| 113 |
|
| 114 |
ASSERT_EQ(1u, matchList.size()); |
| 115 |
EXPECT_EQ(matchList.front().value<int>(), 2); |
| 116 |
} |
| 117 |
{ |
| 118 |
sierra::String name("DEF_3"); |
| 119 |
sierra::Rsrc2::ResourceList matchList; |
| 120 |
resourceList.match(name, matchList); |
| 121 |
|
| 122 |
ASSERT_EQ(1u, matchList.size()); |
| 123 |
EXPECT_EQ(matchList.front().value<int>(), 3); |
| 124 |
} |
| 125 |
} |
| 126 |
|