| 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" // for Test, AssertionResult, SuiteApiResolver |
| 36 |
#include "stk_util/parallel/Parallel.hpp" // for MPI_COMM_WORLD, parallel_machine_rank |
| 37 |
#include "stk_util/parallel/ParallelReduce.hpp" // for all_write_string |
| 38 |
#include "stk_util/parallel/mpi_filebuf.hpp" // for add_aprepro_defines |
| 39 |
#include <cstddef> // for size_t |
| 40 |
#include <iostream> // for ostringstream, operator<<, flush, basic_... |
| 41 |
#include <string> // for string |
| 42 |
|
| 43 |
#if !defined(NOT_HAVE_STK_SEACASAPREPRO_LIB) |
| 44 |
#include "aprepro.h" // for Aprepro |
| 45 |
#endif |
| 46 |
|
| 47 |
TEST(UnitTestParallel, testUnit) |
| 48 |
{ |
| 49 |
int mpi_rank = stk::parallel_machine_rank(MPI_COMM_WORLD); |
| 50 |
int mpi_size = stk::parallel_machine_size(MPI_COMM_WORLD); |
| 51 |
|
| 52 |
std::string s; |
| 53 |
std::ostringstream strout; |
| 54 |
|
| 55 |
std::cout << "all_write_string " << std::flush; |
| 56 |
|
| 57 |
// for (size_t i = 0; i < 250000; ++i) { |
| 58 |
for (size_t i = 0; i < 100; ++i) { |
| 59 |
if (mpi_rank == 0 && i%1000 == 0) |
| 60 |
std::cout << "." << std::flush; |
| 61 |
|
| 62 |
stk::all_write_string(MPI_COMM_WORLD, strout, s); |
| 63 |
} |
| 64 |
|
| 65 |
ASSERT_LT(mpi_rank, mpi_size); |
| 66 |
} |
| 67 |
|
| 68 |
#if !defined(NOT_HAVE_STK_SEACASAPREPRO_LIB) |
| 69 |
TEST(UnitTestParallel, apreproDefines_singleSubstitution) |
| 70 |
{ |
| 71 |
const std::string defines = "a=b"; |
| 72 |
|
| 73 |
SEAMS::Aprepro aprepro; |
| 74 |
stk::add_aprepro_defines(aprepro, defines); |
| 75 |
|
| 76 |
const std::string inputString = "{a}"; |
| 77 |
|
| 78 |
std::string errorString; |
| 79 |
bool success = aprepro.parse_string(inputString, errorString); |
| 80 |
ASSERT_TRUE(success); |
| 81 |
|
| 82 |
ASSERT_EQ(aprepro.parsing_results().str(), "b"); |
| 83 |
} |
| 84 |
|
| 85 |
TEST(UnitTestParallel, apreproDefines_twoSubstitutions) |
| 86 |
{ |
| 87 |
const std::string defines = "a=b, c=d"; |
| 88 |
|
| 89 |
SEAMS::Aprepro aprepro; |
| 90 |
stk::add_aprepro_defines(aprepro, defines); |
| 91 |
|
| 92 |
const std::string inputString = "{a}={c}"; |
| 93 |
|
| 94 |
std::string errorString; |
| 95 |
bool success = aprepro.parse_string(inputString, errorString); |
| 96 |
ASSERT_TRUE(success); |
| 97 |
|
| 98 |
ASSERT_EQ(aprepro.parsing_results().str(), "b=d"); |
| 99 |
} |
| 100 |
|
| 101 |
TEST(UnitTestParallel, apreproDefines_numericSubstitution) |
| 102 |
{ |
| 103 |
const std::string defines = "a=1.23"; |
| 104 |
|
| 105 |
SEAMS::Aprepro aprepro; |
| 106 |
stk::add_aprepro_defines(aprepro, defines); |
| 107 |
|
| 108 |
const std::string inputString = "{a}"; |
| 109 |
|
| 110 |
std::string errorString; |
| 111 |
bool success = aprepro.parse_string(inputString, errorString); |
| 112 |
ASSERT_TRUE(success); |
| 113 |
|
| 114 |
ASSERT_EQ(aprepro.parsing_results().str(), "1.23"); |
| 115 |
} |
| 116 |
|
| 117 |
TEST(UnitTestParallel, apreproDefines_badNumericSubstitution) |
| 118 |
{ |
| 119 |
const std::string defines = "a=1_23"; |
| 120 |
|
| 121 |
SEAMS::Aprepro aprepro; |
| 122 |
stk::add_aprepro_defines(aprepro, defines); |
| 123 |
|
| 124 |
const std::string inputString = "{a}"; |
| 125 |
|
| 126 |
std::string errorString; |
| 127 |
bool success = aprepro.parse_string(inputString, errorString); |
| 128 |
ASSERT_TRUE(success); |
| 129 |
|
| 130 |
ASSERT_EQ(aprepro.parsing_results().str(), "1_23"); |
| 131 |
} |
| 132 |
|
| 133 |
TEST(UnitTestParallel, apreproDefines_mathSubstitution) |
| 134 |
{ |
| 135 |
const std::string defines = "a=1.23"; |
| 136 |
|
| 137 |
SEAMS::Aprepro aprepro; |
| 138 |
stk::add_aprepro_defines(aprepro, defines); |
| 139 |
|
| 140 |
const std::string inputString = "{a*2}"; |
| 141 |
|
| 142 |
std::string errorString; |
| 143 |
bool success = aprepro.parse_string(inputString, errorString); |
| 144 |
ASSERT_TRUE(success); |
| 145 |
|
| 146 |
ASSERT_EQ(aprepro.parsing_results().str(), "2.46"); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
TEST(UnitTestParallel, apreproDefines_badMathSubstitution) |
| 151 |
{ |
| 152 |
const std::string defines = "a=1_23"; |
| 153 |
|
| 154 |
SEAMS::Aprepro aprepro; |
| 155 |
stk::add_aprepro_defines(aprepro, defines); |
| 156 |
|
| 157 |
const std::string inputString = "{a*2}"; |
| 158 |
|
| 159 |
std::string errorString; |
| 160 |
bool success = aprepro.parse_string(inputString, errorString); |
| 161 |
ASSERT_TRUE(success); |
| 162 |
|
| 163 |
ASSERT_EQ(aprepro.parsing_results().str(), ""); |
| 164 |
} |
| 165 |
#endif |
| 166 |
|