mirror of
				https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
				synced 2025-11-04 04:27:48 +00:00 
			
		
		
		
	* Port buffer test to use Catch2 * Move compacted topic processor test to Catch2 * Move configuration tests to Catch2 * Rename configuration test cases * Move topic partition list test to Catch2 * Move handle base tests to Catch2 * Move producer tests to Catch2 * Move consumer tests to catch2 * Use CHECK on tests when appropriate * Remove googletest * Show tests' progress as they run * Update message when Catch2 is not checked out * Remove references to googletest * Run cppkafka_tests manually on travis * Print amount of time taken by each test case
		
			
				
	
	
		
			69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <string>
 | 
						|
#include <vector>
 | 
						|
#include <sstream>
 | 
						|
#include <catch.hpp>
 | 
						|
#include "cppkafka/buffer.h"
 | 
						|
 | 
						|
using std::string;
 | 
						|
using std::vector;
 | 
						|
using std::ostringstream;
 | 
						|
 | 
						|
using namespace cppkafka;
 | 
						|
 | 
						|
TEST_CASE("conversions", "[buffer]") {
 | 
						|
    const string data = "Hello world!";
 | 
						|
    const Buffer buffer(data);
 | 
						|
    const Buffer empty_buffer;
 | 
						|
 | 
						|
 | 
						|
    SECTION("bool conversion") {
 | 
						|
        CHECK(!!buffer == true);
 | 
						|
        CHECK(!!empty_buffer == false);
 | 
						|
    }
 | 
						|
 | 
						|
    SECTION("string conversion") {
 | 
						|
        CHECK(static_cast<string>(buffer) == data);
 | 
						|
        CHECK(static_cast<string>(empty_buffer).empty());
 | 
						|
    }
 | 
						|
 | 
						|
    SECTION("vector conversion") {
 | 
						|
        const vector<char> buffer_as_vector = buffer;
 | 
						|
        CHECK(string(buffer_as_vector.begin(), buffer_as_vector.end()) == data);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
TEST_CASE("construction", "[buffer]") {
 | 
						|
    const string str_data = "Hello world!";
 | 
						|
    const vector<uint8_t> data(str_data.begin(), str_data.end());
 | 
						|
    const Buffer buffer(data);
 | 
						|
    CHECK(str_data == buffer);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TEST_CASE("comparison", "[buffer]") {
 | 
						|
    const string data = "Hello world!";
 | 
						|
    const Buffer buffer1(data);
 | 
						|
    const Buffer buffer2(data);
 | 
						|
    const Buffer empty_buffer;
 | 
						|
 | 
						|
    SECTION("equality") {
 | 
						|
        CHECK(buffer1 == buffer2);
 | 
						|
        CHECK(buffer2 == buffer1);
 | 
						|
    }
 | 
						|
 | 
						|
    SECTION("inequality") {
 | 
						|
        CHECK(buffer1 != empty_buffer);
 | 
						|
        CHECK(empty_buffer != buffer1);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
TEST_CASE("stream extraction", "[buffer]") {
 | 
						|
    const string data = "Hello \x7fwor\x03ld!";
 | 
						|
    const string pretty_string = "Hello \\x7fwor\\x03ld!";
 | 
						|
    const Buffer buffer(data);
 | 
						|
 | 
						|
    ostringstream output;
 | 
						|
    output << buffer;
 | 
						|
    CHECK(output.str() == pretty_string );
 | 
						|
}
 |