Skip to content
Snippets Groups Projects
OdfIOTest.cpp 2.19 KiB
Newer Older
Brown's avatar
Brown committed
#include "Nemesis/gtest/Gtest_Functions.hh"
#include "Nemesis/gtest/nemesis_gtest.hh"
Brown's avatar
Brown committed
#include "../OdfIO.h"
Brown's avatar
Brown committed

/*******************************************************************************
 * Test whether we read floats with VAX format properly
 ******************************************************************************/
Brown's avatar
Brown committed
TEST(OdfIO,readFloatVax)
Brown's avatar
Brown committed
{
Brown's avatar
Brown committed
    sammy::OdfIO odf;
Brown's avatar
Brown committed
    bool is_unix = false;
    double readVal;
    float * dummy;
    double gold;
    char byte1 = 0b00000001;
    char byte2 = 0b00000010;
    char byte3 = 0b00000011;
    char byte4 = 0b00000100;
    //                  |       |       |       |
    int vax =  0b00000001000000010000010000000011; 
    // byte order     2--,      1,      4,      3 

    std::stringstream in;
    in << byte1 << byte2 << byte3 << byte4;
Brown's avatar
Brown committed

    readVal = odf.readFloat(in,is_unix);

    dummy = (float *) &vax;
    gold = *dummy;

    ASSERT_EQ( readVal, gold );
}

/*******************************************************************************
 * Test whether we read floats with UNIX format properly
 ******************************************************************************/
Brown's avatar
Brown committed
TEST(OdfIO,readFloatUnix)
Brown's avatar
Brown committed
{
Brown's avatar
Brown committed
    sammy::OdfIO odf;
Brown's avatar
Brown committed
    bool is_unix = true;
    double readVal;
    float * dummy;
    double gold;
    char byte1 = 0b00000001;
    char byte2 = 0b00000010;
    char byte3 = 0b00000011;
    char byte4 = 0b00000100;
    //                   |       |       |       |
    int unix =  0b00000100000000110000001000000001;

    std::stringstream in;
    in << byte1 << byte2 << byte3 << byte4;
Brown's avatar
Brown committed

    readVal = odf.readFloat(in,is_unix);

    dummy = (float *) &unix;
    gold = *dummy;

    ASSERT_EQ( readVal, gold );
}

/*******************************************************************************
 * Test whether we read integers right
 ******************************************************************************/
Brown's avatar
Brown committed
TEST(OdfIO,readInteger)
Brown's avatar
Brown committed
{
Brown's avatar
Brown committed
    sammy::OdfIO odf;
Brown's avatar
Brown committed
    int gold = 16909060;
    char byte1 = 0b00000001;
    char byte2 = 0b00000010;
    char byte3 = 0b00000011;
    char byte4 = 0b00000100;
Brown's avatar
Brown committed
    int readVal;

    std::stringstream in;
    in << byte4 << byte3 << byte2 << byte1;
Brown's avatar
Brown committed

    readVal = odf.readInteger(in);

    ASSERT_EQ( readVal, gold );
}