root / test / wax_test.cpp @ 259f5bab
History | View | Annotate | Download (3.08 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <boost/test/unit_test.hpp> |
| 19 |
#include <uhd/wax.hpp> |
| 20 |
|
| 21 |
enum opt_a_t{OPTION_A_0, OPTION_A_1};
|
| 22 |
enum opt_b_t{OPTION_B_0, OPTION_B_1};
|
| 23 |
|
| 24 |
BOOST_AUTO_TEST_CASE(test_enums){
|
| 25 |
wax::obj opta = OPTION_A_0; |
| 26 |
BOOST_CHECK_THROW(wax::cast<opt_b_t>(opta), wax::bad_cast); |
| 27 |
BOOST_CHECK_EQUAL(wax::cast<opt_a_t>(opta), OPTION_A_0); |
| 28 |
} |
| 29 |
|
| 30 |
/***********************************************************************
|
| 31 |
* demo class for wax framework
|
| 32 |
**********************************************************************/
|
| 33 |
class wax_demo : public wax::obj{ |
| 34 |
private:
|
| 35 |
std::vector<float> d_nums;
|
| 36 |
std::vector<wax_demo> d_subs; |
| 37 |
public:
|
| 38 |
wax_demo(size_t sub_demos, size_t len){
|
| 39 |
d_nums = std::vector<float>(len);
|
| 40 |
if (sub_demos != 0){ |
| 41 |
for (size_t i = 0; i < len; i++){ |
| 42 |
d_subs.push_back(wax_demo(sub_demos-1, len));
|
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
~wax_demo(void){
|
| 47 |
/* NOP */
|
| 48 |
} |
| 49 |
void get(const wax::obj &key, wax::obj &value){ |
| 50 |
if (d_subs.size() == 0){ |
| 51 |
value = d_nums[wax::cast<size_t>(key)]; |
| 52 |
}else{
|
| 53 |
value = d_subs[wax::cast<size_t>(key)].get_link(); |
| 54 |
} |
| 55 |
} |
| 56 |
void set(const wax::obj &key, const wax::obj &value){ |
| 57 |
if (d_subs.size() == 0){ |
| 58 |
d_nums[wax::cast<size_t>(key)] = wax::cast<float>(value);
|
| 59 |
}else{
|
| 60 |
throw std::runtime_error("cant set to a wax demo with sub demos"); |
| 61 |
} |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
static wax_demo wd(2, 10); |
| 66 |
|
| 67 |
BOOST_AUTO_TEST_CASE(test_chaining){
|
| 68 |
std::cout << "chain 1" << std::endl;
|
| 69 |
wd[size_t(0)];
|
| 70 |
std::cout << "chain 2" << std::endl;
|
| 71 |
wd[size_t(0)][size_t(0)]; |
| 72 |
std::cout << "chain 3" << std::endl;
|
| 73 |
wd[size_t(0)][size_t(0)][size_t(0)]; |
| 74 |
} |
| 75 |
|
| 76 |
BOOST_AUTO_TEST_CASE(test_set_get){
|
| 77 |
std::cout << "set and get all" << std::endl;
|
| 78 |
for (size_t i = 0; i < 10; i++){ |
| 79 |
for (size_t j = 0; j < 10; j++){ |
| 80 |
for (size_t k = 0; k < 10; k++){ |
| 81 |
float val = i * j * k + i + j + k;
|
| 82 |
//std::cout << i << " " << j << " " << k << std::endl;
|
| 83 |
wd[i][j][k] = val; |
| 84 |
BOOST_CHECK_EQUAL(val, wax::cast<float>(wd[i][j][k]));
|
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
BOOST_AUTO_TEST_CASE(test_proxy){
|
| 91 |
std::cout << "store proxy" << std::endl;
|
| 92 |
wax::obj p = wd[size_t(0)][size_t(0)]; |
| 93 |
p[size_t(0)] = float(5); |
| 94 |
|
| 95 |
std::cout << "assign proxy" << std::endl;
|
| 96 |
wax::obj a = p[size_t(0)];
|
| 97 |
BOOST_CHECK_EQUAL(wax::cast<float>(a), float(5)); |
| 98 |
} |