| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_TEST_FIXTURE_H |
| 18 |
#define AAPT_TEST_FIXTURE_H |
| 19 |
|
| 20 |
#include "android-base/file.h" |
| 21 |
#include "android-base/macros.h" |
| 22 |
#include "androidfw/StringPiece.h" |
| 23 |
#include "gmock/gmock.h" |
| 24 |
#include "gtest/gtest.h" |
| 25 |
|
| 26 |
#include "io/Util.h" |
| 27 |
#include "util/Files.h" |
| 28 |
#include "LoadedApk.h" |
| 29 |
|
| 30 |
namespace aapt { |
| 31 |
|
| 32 |
class TestDirectoryFixture : public ::testing::Test { |
| 33 |
public: |
| 34 |
TestDirectoryFixture() = default; |
| 35 |
~TestDirectoryFixture() override = default; |
| 36 |
|
| 37 |
|
| 38 |
void SetUp() override; |
| 39 |
|
| 40 |
|
| 41 |
void TearDown() override; |
| 42 |
|
| 43 |
|
| 44 |
android::StringPiece GetTestDirectory() { |
| 45 |
return temp_dir_; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
std::string GetTestPath(const android::StringPiece& path) { |
| 52 |
std::string base = temp_dir_; |
| 53 |
for (android::StringPiece part : util::Split(path, '/')) { |
| 54 |
file::AppendPath(&base, part); |
| 55 |
} |
| 56 |
return base; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
void WriteFile(const std::string& path, const std::string& contents); |
| 62 |
|
| 63 |
private: |
| 64 |
std::string temp_dir_; |
| 65 |
DISALLOW_COPY_AND_ASSIGN(TestDirectoryFixture); |
| 66 |
}; |
| 67 |
|
| 68 |
class CommandTestFixture : public TestDirectoryFixture { |
| 69 |
public: |
| 70 |
CommandTestFixture() = default; |
| 71 |
~CommandTestFixture() override = default; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
bool CompileFile(const std::string& path, const std::string& contents, |
| 76 |
const android::StringPiece& flat_out_dir, IDiagnostics* diag); |
| 77 |
|
| 78 |
|
| 79 |
bool Link(const std::vector<std::string>& args, IDiagnostics* diag); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
bool Link(const std::vector<std::string>& args, const android::StringPiece& flat_dir, |
| 84 |
IDiagnostics* diag); |
| 85 |
|
| 86 |
|
| 87 |
std::string GetDefaultManifest(const char* package_name = kDefaultPackageName); |
| 88 |
|
| 89 |
|
| 90 |
std::unique_ptr<io::IData> OpenFileAsData(LoadedApk* apk, |
| 91 |
const android::StringPiece& path); |
| 92 |
|
| 93 |
|
| 94 |
void AssertLoadXml(LoadedApk* apk, const io::IData* data, |
| 95 |
android::ResXMLTree* out_tree); |
| 96 |
|
| 97 |
static const char* kDefaultPackageName; |
| 98 |
private: |
| 99 |
DISALLOW_COPY_AND_ASSIGN(CommandTestFixture); |
| 100 |
}; |
| 101 |
|
| 102 |
struct ManifestBuilder { |
| 103 |
explicit ManifestBuilder(CommandTestFixture* fixture); |
| 104 |
ManifestBuilder& AddContents(const std::string& contents); |
| 105 |
ManifestBuilder& SetPackageName(const std::string& package_name); |
| 106 |
std::string Build(const std::string& file_path); |
| 107 |
std::string Build(); |
| 108 |
|
| 109 |
private: |
| 110 |
CommandTestFixture* fixture_; |
| 111 |
std::string package_name_ = CommandTestFixture::kDefaultPackageName; |
| 112 |
std::string contents_; |
| 113 |
}; |
| 114 |
|
| 115 |
struct LinkCommandBuilder { |
| 116 |
explicit LinkCommandBuilder(CommandTestFixture* fixture); |
| 117 |
LinkCommandBuilder& AddCompiledResDir(const std::string& dir, IDiagnostics* diag); |
| 118 |
LinkCommandBuilder& AddFlag(const std::string& flag); |
| 119 |
LinkCommandBuilder& AddParameter(const std::string& param, const std::string& value); |
| 120 |
LinkCommandBuilder& SetManifestFile(const std::string& manifest_path); |
| 121 |
std::vector<std::string> Build(const std::string& out_apk_path); |
| 122 |
|
| 123 |
private: |
| 124 |
CommandTestFixture* fixture_; |
| 125 |
std::vector<std::string> args_; |
| 126 |
bool manifest_supplied_ = false; |
| 127 |
}; |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
#endif |