• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #define BOOST_TEST_MODULE TestString
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/container/string.hpp>
15 #include <boost/compute/container/basic_string.hpp>
16 #include <boost/test/output_test_stream.hpp>
17 
18 #include "context_setup.hpp"
19 #include "check_macros.hpp"
20 
21 using boost::test_tools::output_test_stream;
22 
BOOST_AUTO_TEST_CASE(empty)23 BOOST_AUTO_TEST_CASE(empty)
24 {
25     boost::compute::string str;
26     BOOST_VERIFY(str.empty());
27 }
28 
BOOST_AUTO_TEST_CASE(swap)29 BOOST_AUTO_TEST_CASE(swap)
30 {
31     // boost::compute::string currently uses only default_queue, default_context,
32     // default_device so this overrides queue variable set in
33     // BOOST_FIXTURE_TEST_SUITE(compute_test, Context) in context_setup.hpp
34     // in case it is not the default_queue
35     boost::compute::command_queue& queue =
36         boost::compute::system::default_queue();
37 
38     boost::compute::string str1 = "compute";
39     boost::compute::string str2 = "boost";
40     BOOST_VERIFY(!str2.empty());
41     BOOST_VERIFY(!str2.empty());
42     str1.swap(str2);
43     // this macro uses queue variable and it must be default_queue
44     CHECK_STRING_EQUAL(str1, "boost");
45     CHECK_STRING_EQUAL(str2, "compute");
46     str1.clear();
47     str1.swap(str2);
48     CHECK_STRING_EQUAL(str1, "compute");
49     CHECK_STRING_EQUAL(str2, "");
50     str2.swap(str1);
51     CHECK_STRING_EQUAL(str1, "");
52     CHECK_STRING_EQUAL(str2, "compute");
53     str1.swap(str1);
54     CHECK_STRING_EQUAL(str1, "");
55 }
56 
BOOST_AUTO_TEST_CASE(size)57 BOOST_AUTO_TEST_CASE(size)
58 {
59     boost::compute::string str = "string";
60     BOOST_VERIFY(!str.empty());
61     BOOST_CHECK_EQUAL(str.size(), size_t(6));
62     BOOST_CHECK_EQUAL(str.length(), size_t(6));
63 }
64 
BOOST_AUTO_TEST_CASE(find_doctest)65 BOOST_AUTO_TEST_CASE(find_doctest)
66 {
67 //! [string_find]
68 boost::compute::string str = "boost::compute::string";
69 int pos = str.find("::");
70 //! [string_find]
71     boost::compute::string pattern = "string";
72     BOOST_VERIFY(!str.empty());
73     BOOST_CHECK_EQUAL(str.find('o'), 1);
74     BOOST_CHECK_NE(str.find('o'), 2);
75     BOOST_CHECK_EQUAL(str.find(pattern), 16);
76     BOOST_CHECK_EQUAL(pos, 5);
77     BOOST_CHECK_EQUAL(str.find("@#$"), size_t(-1));
78 }
79 
BOOST_AUTO_TEST_CASE(outStream)80 BOOST_AUTO_TEST_CASE(outStream)
81 {
82     output_test_stream output;
83     boost::compute::string str = "string";
84     output<<str;
85     BOOST_CHECK(output.is_equal("string"));
86     BOOST_VERIFY(!output.is_equal("!@$%"));
87 }
88 
89 BOOST_AUTO_TEST_SUITE_END()
90