IAP GITLAB

Commit 15ca93e3 authored by Ralf M Ulrich's avatar Ralf M Ulrich

style

parent 8b76a9ca
Pipeline #3298 failed with stage
in 2 minutes and 43 seconds
......@@ -23,81 +23,78 @@
#include "gzstream.hpp"
#include "bzstream.hpp"
#include <algorithm>
#include <iterator>
#include <string>
#include <fstream>
template<typename InputIterator1, typename InputIterator2>
bool
range_equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{
while(first1 != last1 && first2 != last2)
{
if(*first1 != *first2) return false;
++first1;
++first2;
}
return (first1 == last1) && (first2 == last2);
template <typename InputIterator1, typename InputIterator2>
bool range_equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
InputIterator2 last2) {
while (first1 != last1 && first2 != last2) {
if (*first1 != *first2) return false;
++first1;
++first2;
}
return (first1 == last1) && (first2 == last2);
}
bool compare_files(const std::string& filename1, const std::string& filename2)
{
std::ifstream file1(filename1);
std::ifstream file2(filename2);
bool compare_files(const std::string& filename1, const std::string& filename2) {
std::ifstream file1(filename1);
std::ifstream file2(filename2);
std::istreambuf_iterator<char> begin1(file1);
std::istreambuf_iterator<char> begin2(file2);
std::istreambuf_iterator<char> begin1(file1);
std::istreambuf_iterator<char> begin2(file2);
std::istreambuf_iterator<char> end;
std::istreambuf_iterator<char> end;
return range_equal(begin1, end, begin2, end);
return range_equal(begin1, end, begin2, end);
}
void test_out(bool result, std::string message)
{
if(result)
{
std::cout<<"\033[32m"<<message<<": Passed"<<"\033[0m"<<std::endl;
}
else
{
std::cout<<"\033[31m"<<message<<": Failled"<<"\033[0m"<<std::endl;
}
void test_out(bool result, std::string message) {
if (result) {
std::cout << "\033[32m" << message << ": Passed"
<< "\033[0m" << std::endl;
} else {
std::cout << "\033[31m" << message << ": Failled"
<< "\033[0m" << std::endl;
}
}
int main(int argc, char** argv)
{
std::string message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae erat sit amet lorem vehicula malesuada. Praesent tempus, tortor sed dapibus molestie, tortor sem sagittis velit, eget dapibus est odio aliquet magna. Morbi sed malesuada quam, nec rhoncus ligula. Ut non fermentum metus. Suspendisse potenti. Nam auctor facilisis lorem fermentum.";
/* write a message */
ogzstream out_gz("out.gz");
obzstream out_bz("out.bz");
out_gz<<message<<std::endl;
out_bz<<message<<std::endl;
out_gz.close();
out_bz.close();
/* read message */
igzstream in_gz("out.gz");
ibzstream in_bz("out.bz");
std::string gzread_message;
std::getline(in_gz, gzread_message);
std::string bzread_message;
std::getline(in_bz, bzread_message);
/* check */
/* created file to reference file */
test_out(compare_files("out.gz", "reference.gz"), "gzip file same as reference");
test_out(compare_files("out.bz", "reference.bz"), "bzip file same as reference");
/* read message to write message */
test_out(gzread_message == message, "gz message read same as original");
test_out(bzread_message == message, "bz message read same as original");
int main(int argc, char** argv) {
std::string message =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae erat sit "
"amet lorem vehicula malesuada. Praesent tempus, tortor sed dapibus molestie, "
"tortor sem sagittis velit, eget dapibus est odio aliquet magna. Morbi sed "
"malesuada quam, nec rhoncus ligula. Ut non fermentum metus. Suspendisse potenti. "
"Nam auctor facilisis lorem fermentum.";
/* write a message */
ogzstream out_gz("out.gz");
obzstream out_bz("out.bz");
out_gz << message << std::endl;
out_bz << message << std::endl;
out_gz.close();
out_bz.close();
/* read message */
igzstream in_gz("out.gz");
ibzstream in_bz("out.bz");
std::string gzread_message;
std::getline(in_gz, gzread_message);
std::string bzread_message;
std::getline(in_bz, bzread_message);
/* check */
/* created file to reference file */
test_out(compare_files("out.gz", "reference.gz"), "gzip file same as reference");
test_out(compare_files("out.bz", "reference.bz"), "bzip file same as reference");
/* read message to write message */
test_out(gzread_message == message, "gz message read same as original");
test_out(bzread_message == message, "bz message read same as original");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment