"Fossies" - the Fresh Open Source Software Archive

Member "proj-6.2.1/test/unit/test_primitives.hpp" (6 Mar 2019, 3902 Bytes) of package /linux/privat/proj-6.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /******************************************************************************
    2  *
    3  * Project:  PROJ
    4  * Purpose:  Test ISO19111:2018 implementation
    5  * Author:   Even Rouault <even dot rouault at spatialys dot com>
    6  *
    7  ******************************************************************************
    8  * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com>
    9  *
   10  * Permission is hereby granted, free of charge, to any person obtaining a
   11  * copy of this software and associated documentation files (the "Software"),
   12  * to deal in the Software without restriction, including without limitation
   13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   14  * and/or sell copies of the Software, and to permit persons to whom the
   15  * Software is furnished to do so, subject to the following conditions:
   16  *
   17  * The above copyright notice and this permission notice shall be included
   18  * in all copies or substantial portions of the Software.
   19  *
   20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   26  * DEALINGS IN THE SOFTWARE.
   27  ****************************************************************************/
   28 
   29 #include "gtest_include.h"
   30 
   31 #ifndef FROM_PROJ_CPP
   32 #define FROM_PROJ_CPP
   33 #endif
   34 
   35 #include "proj/internal/internal.hpp"
   36 
   37 #include <cmath>
   38 #include <cstdlib>
   39 
   40 using namespace osgeo::proj::internal;
   41 
   42 static ::testing::AssertionResult ComparePROJString(const char* m_expr,
   43                                                     const char* n_expr,
   44                                                     const std::string& m,
   45                                                     const std::string& n) {
   46     //if (m == n) return ::testing::AssertionSuccess();
   47     auto mTokens = split(m, ' ');
   48     auto nTokens = split(n, ' ');
   49     if( mTokens.size() == nTokens.size() )
   50     {
   51         bool success = true;
   52         for( size_t i = 0; i < mTokens.size(); i++ )
   53         {
   54             auto mSubTokens = split(mTokens[i], '=');
   55             auto nSubTokens = split(nTokens[i], '=');
   56             if( mSubTokens.size() != nSubTokens.size() ) {
   57                 success = false;
   58                 break;
   59             }
   60             if( mSubTokens.size() == 2 && nSubTokens.size() == 2 ) {
   61                 if( mSubTokens[0] != nSubTokens[0] ) {
   62                     success = false;
   63                     break;
   64                 }
   65                 double mValue = 0.0;
   66                 bool mIsDouble = false;
   67                 try {
   68                     mValue = c_locale_stod(mSubTokens[1]);
   69                     mIsDouble = true;
   70                 } catch( const std::exception &) {}
   71                 double nValue = 0.0;
   72                 bool nIsDouble = false;
   73                 try {
   74                     nValue = c_locale_stod(nSubTokens[1]);
   75                     nIsDouble = true;
   76                 } catch( const std::exception &) {}
   77                 if( mIsDouble != nIsDouble ) {
   78                     success = false;
   79                     break;
   80                 }
   81                 if( mIsDouble ) {
   82                     success = std::abs(mValue - nValue) <= 1e-14 * std::abs(mValue);
   83                 } else {
   84                     success = mSubTokens[1] == nSubTokens[1];
   85                 }
   86                 if( !success ) {
   87                     break;
   88                 }
   89             }
   90         }
   91 
   92         if( success ) {
   93             return ::testing::AssertionSuccess();
   94         }
   95     }
   96 
   97     return ::testing::AssertionFailure() << m_expr << " and " << n_expr
   98         << " (" << m << " and " << n << ") are different";
   99 }