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

Commit b34af7c1 authored by Kevin Rocard's avatar Kevin Rocard
Browse files

Audio V4: Make test helper version independent

Bug: 38184704
Test: compile
Change-Id: Ia9ec81ccbad1d7411fdc570ae6dd728dd1520065
parent 6891d7ec
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <initializer_list>
#include <limits>
#include <string>
#include <vector>
@@ -40,9 +41,11 @@
#include "utility/AssertOk.h"
#include "utility/Documentation.h"
#include "utility/EnvironmentTearDown.h"
#define AUDIO_HAL_VERSION V2_0
#include "utility/PrettyPrintAudioTypes.h"
#include "utility/ReturnIn.h"

using std::initializer_list;
using std::string;
using std::to_string;
using std::vector;
@@ -856,7 +859,7 @@ TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail",
               ASSERT_IS_OK(device->getHwAvSync()));

static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys,
                                vector<Result> expectedResults) {
                                initializer_list<Result> expectedResults) {
    hidl_vec<ParameterValue> parameters;
    Result res;
    ASSERT_OK(stream->getParameters(keys, returnIn(res, parameters)));
@@ -924,8 +927,7 @@ TEST_IO_STREAM(RemoveNonExistingEffect,
TEST_IO_STREAM(standby, "Make sure the stream can be put in stanby",
               ASSERT_OK(stream->standby()))  // can not fail

static vector<Result> invalidStateOrNotSupported = {Result::INVALID_STATE,
                                                    Result::NOT_SUPPORTED};
static constexpr auto invalidStateOrNotSupported = {Result::INVALID_STATE, Result::NOT_SUPPORTED};

TEST_IO_STREAM(startNoMmap,
               "Starting a mmaped stream before mapping it should fail",
+1 −1
Original line number Diff line number Diff line
//
// Copyright (C) 2017 The Android Open Source Project
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
+10 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#define ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_ASSERTOK_H

#include <algorithm>
#include <vector>
#include <initializer_list>

#include <hidl/Status.h>

@@ -33,7 +33,6 @@ namespace detail {
// This is a detail namespace, thus it is OK to import a class as nobody else is
// allowed to use it
using ::android::hardware::Return;
using ::android::hardware::audio::V2_0::Result;

template <class T>
inline ::testing::AssertionResult assertIsOk(const char* expr, const Return<T>& ret) {
@@ -50,6 +49,7 @@ inline ::testing::AssertionResult continueIfIsOk(const char* expr, const Return<
}

// Expect two equal Results
template <class Result>
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
                                               Result expected, Result result) {
    return ::testing::AssertionResult(expected == result)
@@ -58,6 +58,7 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
}

// Expect two equal Results one being wrapped in an OK Return
template <class Result>
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
                                               Result expected, const Return<Result>& ret) {
    return continueIfIsOk(r_expr, ret,
@@ -65,8 +66,10 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
}

// Expect a Result to be part of a list of Results
template <class Result>
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
                                               const std::vector<Result>& expected, Result result) {
                                               const std::initializer_list<Result>& expected,
                                               Result result) {
    if (std::find(expected.begin(), expected.end(), result) != expected.end()) {
        return ::testing::AssertionSuccess();  // result is in expected
    }
@@ -77,8 +80,9 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
}

// Expect a Result wrapped in an OK Return to be part of a list of Results
template <class Result>
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
                                               const std::vector<Result>& expected,
                                               const std::initializer_list<Result>& expected,
                                               const Return<Result>& ret) {
    return continueIfIsOk(r_expr, ret,
                          [&] { return assertResult(e_expr, r_expr, expected, Result{ret}); });
@@ -88,11 +92,13 @@ inline ::testing::AssertionResult assertOk(const char* expr, const Return<void>&
    return assertIsOk(expr, ret);
}

template <class Result>
inline ::testing::AssertionResult assertOk(const char* expr, Result result) {
    return ::testing::AssertionResult(result == Result::OK)
           << "Expected success: " << expr << "\nActual: " << ::testing::PrintToString(result);
}

template <class Result>
inline ::testing::AssertionResult assertOk(const char* expr, const Return<Result>& ret) {
    return continueIfIsOk(expr, ret, [&] { return assertOk(expr, Result{ret}); });
}
Loading