1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/**
* (c) 2013 by Mega Limited, Auckland, New Zealand
*
* This file is part of MEGAcmd.
*
* MEGAcmd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "MegaCmdTestingTools.h"
#include "TestUtils.h"
class CatTests : public NOINTERACTIVELoggedInTest
{
SelfDeletingTmpFolder mTmpDir;
void SetUp() override
{
NOINTERACTIVELoggedInTest::SetUp();
TearDown();
}
void TearDown() override
{
auto result = executeInClient({"rm", "-f", fileName});
NOINTERACTIVELoggedInTest::TearDown();
}
protected:
const std::string fileName = "file.txt";
fs::path localPath() const
{
return mTmpDir.path();
}
};
TEST_F(CatTests, NoFile)
{
auto result = executeInClient({"cat", fileName});
ASSERT_FALSE(result.ok());
}
TEST_F(CatTests, AsciiContents)
{
const fs::path filePath = localPath() / "file_ascii.txt";
const std::string contents = "Hello world!";
{
std::ofstream file(filePath);
file << contents;
}
auto result = executeInClient({"put", filePath.string(), fileName});
ASSERT_TRUE(result.ok());
result = executeInClient({"cat", fileName});
ASSERT_TRUE(result.ok());
EXPECT_EQ(contents, result.out());
}
TEST_F(CatTests, NonAsciiContents)
{
const fs::path filePath = localPath() / "file_non_ascii.txt";
const std::string contents = u8"\u3053\u3093\u306b\u3061\u306f\u3001\u4e16\u754c";
{
std::ofstream file(filePath, std::ios::binary);
file << contents;
}
auto result = executeInClient({"put", filePath.string(), fileName});
ASSERT_TRUE(result.ok());
result = executeInClient({"cat", fileName});
ASSERT_TRUE(result.ok());
EXPECT_EQ(contents, result.out());
}
TEST_F(CatTests, NonAsciiContentsWithNewlines)
{
const fs::path filePath = localPath() / "file_non_ascii_newlines.txt";
const std::string contents = u8"\u3053\u3093\u306b\u3061\r\n\u306f\u3001\n\u4e16\u754c";
{
std::ofstream file(filePath, std::ios::binary);
file << contents;
}
auto result = executeInClient({"put", filePath.string(), fileName});
ASSERT_TRUE(result.ok());
result = executeInClient({"cat", fileName});
ASSERT_TRUE(result.ok());
EXPECT_EQ(contents, result.out());
}
|