Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 568b18f0 authored by Manisha Jajoo's avatar Manisha Jajoo
Browse files

WriterTest: remove output file after test completes

Test: atest writerTest -- --enable-module-dynamic-download=true

Bug: 144317323

Change-Id: I663b746a53917645c7f9ceacfd27e6064efa040e
parent 35869dff
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,5 +26,6 @@
        <option name="native-test-device-path" value="/data/local/tmp" />
        <option name="module-name" value="writerTest" />
        <option name="native-test-flag" value="-P /data/local/tmp/WriterTestRes/" />
        <option name="native-test-flag" value="-C true" />
    </test>
</configuration>
+2 −2
Original line number Diff line number Diff line
@@ -25,9 +25,9 @@ Download and extract the folder. Push all the files in this folder to /data/loca
adb push WriterTestRes /data/local/tmp/
```

usage: writerTest -P \<path_to_res_folder\>
usage: writerTest -P \<path_to_res_folder\> -C <remove_output_file>
```
adb shell /data/local/tmp/writerTest -P /data/local/tmp/WriterTestRes/
adb shell /data/local/tmp/writerTest -P /data/local/tmp/WriterTestRes/ -C true
```
Alternatively, the test can also be run using atest command.

+1 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ class WriterTest {
        }
        mBufferInfo.clear();
        if (mInputStream.is_open()) mInputStream.close();
        if (gEnv->cleanUp()) remove(OUTPUT_FILE_NAME);
    }

    void setupWriterType(string writerFormat) {
+15 −4
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ using namespace std;

class WriterTestEnvironment : public ::testing::Environment {
  public:
    WriterTestEnvironment() : res("/data/local/tmp/") {}
    WriterTestEnvironment() : res("/data/local/tmp/"), deleteOutput(true) {}

    // Parses the command line arguments
    int initFromOptions(int argc, char **argv);
@@ -34,16 +34,21 @@ class WriterTestEnvironment : public ::testing::Environment {

    const string getRes() const { return res; }

    bool cleanUp() const { return deleteOutput; }

  private:
    string res;
    bool deleteOutput;
};

int WriterTestEnvironment::initFromOptions(int argc, char **argv) {
    static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
    static struct option options[] = {{"res", required_argument, 0, 'P'},
                                      {"cleanUp", optional_argument, 0, 'C'},
                                      {0, 0, 0, 0}};

    while (true) {
        int index = 0;
        int c = getopt_long(argc, argv, "P:", options, &index);
        int c = getopt_long(argc, argv, "P:C:", options, &index);
        if (c == -1) {
            break;
        }
@@ -52,6 +57,11 @@ int WriterTestEnvironment::initFromOptions(int argc, char **argv) {
            case 'P':
                setRes(optarg);
                break;
            case 'C':
                if (!strcmp(optarg, "false")) {
                    deleteOutput = false;
                }
                break;
            default:
                break;
        }
@@ -62,7 +72,8 @@ int WriterTestEnvironment::initFromOptions(int argc, char **argv) {
                "unrecognized option: %s\n\n"
                "usage: %s <gtest options> <test options>\n\n"
                "test options are:\n\n"
                "-P, --path: Resource files directory location\n",
                "-P, --path: Resource files directory location\n"
                "-C, default:true. Delete output file after test completes\n",
                argv[optind ?: 1], argv[0]);
        return 2;
    }