DotCallTest.cpp 4.24 KB
Newer Older
k06a's avatar
k06a committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <list>
#include <deque>
#include <vector>
#include <string>

#include <gtest/gtest.h>
#include "CommonTests.h"

#include "boolinq.h"

using namespace boolinq;

//////////////////////////////////////////////////////////////////////////

TEST(DotCall, BytesRange)
{
17
    unsigned src[] = {0x12345678,0xAABBCCDD};
k06a's avatar
k06a committed
18 19 20 21 22 23 24 25 26 27 28 29
    int ansFL[] = 
    {
        0x78,0x56,0x34,0x12,
        0xDD,0xCC,0xBB,0xAA,
    };
    int ansLF[] = 
    {
        0x12,0x34,0x56,0x78,
        0xAA,0xBB,0xCC,0xDD,
    };

    auto dstFL1 = from(src).bytes();
30 31
    auto dstFL2 = from(src).bytes(BytesFirstToLast);
    auto dstLF1 = from(src).bytes(BytesLastToFirst);
k06a's avatar
k06a committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

    CheckRangeEqArray(dstFL1, ansFL);
    CheckRangeEqArray(dstFL2, ansFL);
    CheckRangeEqArray(dstLF1, ansLF);
}            

//////////////////////////////////////////////////////////////////////////

TEST(DotCall, UnbytesRange)
{
    unsigned char src[] = 
    {
        0x78,0x56,0x34,0x12,
        0xDD,0xCC,0xBB,0xAA,
    };
47 48
    unsigned ansFL[] = {0x12345678,0xAABBCCDD};
    unsigned ansLF[] = {0x78563412,0xDDCCBBAA};
k06a's avatar
k06a committed
49

50
    auto dstFL1 = from(src).unbytes<unsigned>();
51 52
    auto dstFL2 = from(src).unbytes<unsigned>(BytesFirstToLast);
    auto dstLF1 = from(src).unbytes<unsigned>(BytesLastToFirst);
k06a's avatar
k06a committed
53 54 55 56 57 58 59 60 61 62

    CheckRangeEqArray(dstFL1, ansFL);
    CheckRangeEqArray(dstFL2, ansFL);
    CheckRangeEqArray(dstLF1, ansLF);
} 

//////////////////////////////////////////////////////////////////////////

TEST(DotCall, BitsRangeHL)
{
63
    unsigned src[] = {0xAABBCCDD};
k06a's avatar
k06a committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    int ansFL[] = 
    {
        1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,0,0,
        1,0,1,1,1,0,1,1,
        1,0,1,0,1,0,1,0,
    };
    int ansLF[] = 
    {
        1,0,1,0,1,0,1,0,
        1,0,1,1,1,0,1,1,
        1,1,0,0,1,1,0,0,
        1,1,0,1,1,1,0,1,
    };

    auto dstFL1 = from(src).bits();
80
    auto dstFL2 = from(src).bits(BitsHighToLow);
Anton Bukov's avatar
Anton Bukov committed
81 82
    auto dstFL3 = from(src).bits(BitsHighToLow, BytesFirstToLast);
    auto dstLF1 = from(src).bits(BitsHighToLow, BytesLastToFirst);
k06a's avatar
k06a committed
83 84 85 86 87 88 89 90 91

    CheckRangeEqArray(dstFL1, ansFL);
    CheckRangeEqArray(dstFL2, ansFL);
    CheckRangeEqArray(dstFL3, ansFL);
    CheckRangeEqArray(dstLF1, ansLF);
}

TEST(DotCall, BitsRangeLH)
{
92
    unsigned src[] = {0xAABBCCDD};
k06a's avatar
k06a committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    int ansFL[] = 
    {
        1,0,1,1,1,0,1,1,
        0,0,1,1,0,0,1,1,
        1,1,0,1,1,1,0,1,
        0,1,0,1,0,1,0,1,
    };
    int ansLF[] = 
    {
        0,1,0,1,0,1,0,1,
        1,1,0,1,1,1,0,1,
        0,0,1,1,0,0,1,1,
        1,0,1,1,1,0,1,1,
    };

108
    auto dstFL1 = from(src).bits(BitsLowToHigh);
Anton Bukov's avatar
Anton Bukov committed
109 110
    auto dstFL2 = from(src).bits(BitsLowToHigh, BytesFirstToLast);
    auto dstLF1 = from(src).bits(BitsLowToHigh, BytesLastToFirst);
k06a's avatar
k06a committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

    CheckRangeEqArray(dstFL1, ansFL);
    CheckRangeEqArray(dstFL2, ansFL);
    CheckRangeEqArray(dstLF1, ansLF);
}

//////////////////////////////////////////////////////////////////////////

TEST(DotCall, UnbitsRangeHLFL)
{
    int src[] =
    {
        1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,0,0,
        1,0,1,1,1,0,1,1,
        1,0,1,0,1,0,1,0
    };
    int ans_4b[] = {0xDD,0xCC,0xBB,0xAA};
129 130
    unsigned ans_1i[] = {0xAABBCCDD};
    unsigned ansLF_1i[] = {0xDDCCBBAA};
k06a's avatar
k06a committed
131 132

    auto dst1_4b = from(src).unbits();
133 134
    auto dst2_4b = from(src).unbits(BitsHighToLow);
    auto dst1_1i = from(src).unbits<unsigned>(BitsHighToLow);
Anton Bukov's avatar
Anton Bukov committed
135 136
    auto dst2_1i = from(src).unbits<unsigned>(BitsHighToLow, BytesFirstToLast);
    auto dst3_1i = from(src).unbits<unsigned>(BitsHighToLow, BytesLastToFirst);
k06a's avatar
k06a committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

    CheckRangeEqArray(dst1_4b, ans_4b);
    CheckRangeEqArray(dst2_4b, ans_4b);
    CheckRangeEqArray(dst1_1i, ans_1i);
    CheckRangeEqArray(dst2_1i, ans_1i);
    CheckRangeEqArray(dst3_1i, ansLF_1i);
}

//TEST(DotCall, UnbitsRangeLH)
//{
//    int src[] = {0xAABBCCDD};
//    int ansFL[] = 
//    {
//        1,0,1,1,1,0,1,1,
//        0,0,1,1,0,0,1,1,
//        1,1,0,1,1,1,0,1,
//        0,1,0,1,0,1,0,1,
//    };
//    int ansLF[] = 
//    {
//        0,1,0,1,0,1,0,1,
//        1,1,0,1,1,1,0,1,
//        0,0,1,1,0,0,1,1,
//        1,0,1,1,1,0,1,1,
//    };
//
163 164 165
//    auto dstFL1 = from(src).bits<BitsLowToHigh>();
//    auto dstFL2 = from(src).bits<BitsLowToHigh,BytesFirstToLast>();
//    auto dstLF1 = from(src).bits<BitsLowToHigh,BytesLastToFirst>();
k06a's avatar
k06a committed
166 167 168 169 170 171
//
//    CheckRangeEqArray(dstFL1, ansFL);
//    CheckRangeEqArray(dstFL2, ansFL);
//    CheckRangeEqArray(dstLF1, ansLF);
//}