#include "taper.hh" #include "gtest/gtest.h" #include "utils.h" //#define VERBOSE namespace { class TaperTest : public ::testing::Test { protected: TaperTest() {} virtual ~TaperTest() { // You can do clean-up work that doesn't throw exceptions here. // unlink(fname.c_str()); } // If the constructor and destructor are not enough for setting up // and cleaning up each test, you can define the following methods: virtual void SetUp() { // Code here will be called immediately after the constructor (right // before each test). } virtual void TearDown() { // Code here will be called immediately after each test (right // before the destructor). } // Objects declared here can be used by all tests in the test case for Grid. }; TEST_F(TaperTest, empty) { std::string arg=""; Taper tap(arg); EXPECT_EQ(0,tap.getSize()); } TEST_F(TaperTest, offset) { std::string arg="offset:-2500,-2200,-500,-200"; Taper tap(arg); EXPECT_EQ(1, tap.getSize()); std::string key="offset"; EXPECT_EQ(key, tap[0].key); EXPECT_EQ(-2500,tap[0].t[0]); EXPECT_EQ(-2200,tap[0].t[1]); EXPECT_EQ(-500,tap[0].t[2]); EXPECT_EQ(-200,tap[0].t[3]); } TEST_F(TaperTest, missing_corner) { std::string arg="offset:-2500,-2200,-500"; std::stringstream b; try { Taper tap(arg); } catch (RVL::RVLException & e) { e.write(b); } EXPECT_EQ("ERROR: read_taperdata\n failed to read 4 corner coordinates\n\n", b.str()); } TEST_F(TaperTest, too_many_keys) { std::string arg="gx:offset:-2500,-2200,-500,-200"; stringstream b; try { Taper tap(arg); } catch (RVL::RVLException & e) { e.write(b); } EXPECT_EQ("ERROR: read_taperdata\n failed to read 4 corner coordinates\n\n", b.str()); } TEST_F(TaperTest, gxoffset) { std::string arg="gx:1000,1100,3000,3200;offset:-2500,-2200,-500,-200"; Taper tap(arg); EXPECT_EQ(2, tap.getSize()); std::string key="gx"; EXPECT_EQ(key, tap[0].key); EXPECT_EQ(1000,tap[0].t[0]); EXPECT_EQ(1100,tap[0].t[1]); EXPECT_EQ(3000,tap[0].t[2]); EXPECT_EQ(3200,tap[0].t[3]); key="offset"; EXPECT_EQ(key, tap[1].key); EXPECT_EQ(-2500,tap[1].t[0]); EXPECT_EQ(-2200,tap[1].t[1]); EXPECT_EQ(-500,tap[1].t[2]); EXPECT_EQ(-200,tap[1].t[3]); } } // namespace int main(int argc, char **argv) { #ifdef IWAVE_USE_MPI int ts=0; MPI_Init_thread(&argc,&argv,MPI_THREAD_FUNNELED,&ts); #endif try { ::testing::InitGoogleTest(&argc, argv); #ifdef IWAVE_USE_MPI storeGlobalComm(MPI_COMM_WORLD); storeComm(MPI_COMM_WORLD); #endif int res = RUN_ALL_TESTS(); #ifdef IWAVE_USE_MPI MPI_Finalize(); #endif return res; } catch (RVL::RVLException & e) { e.write(cerr); #ifdef IWAVE_USE_MPI MPI_Abort(MPI_COMM_WORLD,0); MPI_Finalize(); #endif exit(1); } }