Repository: google/filament
File: libs/utils/test/test_Status.cpp (C++)

Code before:
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
 */
#include <gtest/gtest.h>

#include <utils/Status.h>

using namespace utils;

TEST(StatusTest, DefaultConstructorOkStatus) {
    Status actual = Status();
    Status expected = Status(StatusCode::OK, "");
    EXPECT_EQ(actual, expected);
}

TEST(StatusTest, Constructor) {
    std::string_view errorMessage = "invalid";
    Status status = Status(StatusCode::INVALID_ARGUMENT, errorMessage);
    EXPECT_EQ(status.getCode(), StatusCode::INVALID_ARGUMENT);
    EXPECT_EQ(status.getErrorMessage(), errorMessage);
}

TEST(StatusTest, CopyOperator) {
    Status status1 = Status::ok();
    EXPECT_EQ(status1.getCode(), StatusCode::OK);
    EXPECT_EQ(status1.getErrorMessage(), "");

    Status status2 = Status(StatusCode::INTERNAL, "internal error");
    status1 = status2;

    EXPECT_EQ(status1, status2);
}

TEST(StatusTest, CopyConstructor) {
    Status original = Status::internal("internal error");
    Status copy(original);
    EXPECT_EQ(original, copy);
}

TEST(StatusTest, MoveOperator) {
    Status status = Status();
    EXPECT_EQ(status.getCode(), StatusCode::OK);
    EXPECT_EQ(status.getErrorMessage(), "");

Review comment (suggestion):
just curious, why do you not write it like
```
Status stats(StatusCode::INVALID_ARGUMENT, errorMessage); ? 
```

Code after:
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
 */
#include <gtest/gtest.h>

#include <utils/Status.h>

using namespace utils;

TEST(StatusTest, DefaultConstructorOkStatus) {
    Status actual;
    Status expected(StatusCode::OK, "");
    EXPECT_EQ(actual, expected);
}

TEST(StatusTest, Constructor) {
    std::string_view errorMessage = "invalid";
    Status status(StatusCode::INVALID_ARGUMENT, errorMessage);
    EXPECT_EQ(status.getCode(), StatusCode::INVALID_ARGUMENT);
    EXPECT_EQ(status.getErrorMessage(), errorMessage);
}

TEST(StatusTest, CopyOperator) {
    Status status1 = Status::ok();
    EXPECT_EQ(status1.getCode(), StatusCode::OK);
    EXPECT_EQ(status1.getErrorMessage(), "");

    Status status2(StatusCode::INTERNAL, "internal error");
    status1 = status2;

    EXPECT_EQ(status1, status2);
}

TEST(StatusTest, CopyConstructor) {
    Status original = Status::internal("internal error");
    Status copy(original);
    EXPECT_EQ(original, copy);
}

TEST(StatusTest, MoveOperator) {
    Status status;
    EXPECT_EQ(status.getCode(), StatusCode::OK);
    EXPECT_EQ(status.getErrorMessage(), "");