ActsMediaCameraTest.cpp 29.6 KB
Newer Older
W
wenjun 已提交
1
/*
M
mamingshuai 已提交
2
 * Copyright (c) 2021 Huawei Device Co., Ltd.
W
wenjun 已提交
3 4 5 6
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
M
mamingshuai 已提交
7
 *     http://www.apache.org/licenses/LICENSE-2.0
W
wenjun 已提交
8 9 10 11 12 13 14 15 16
 *
 * 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 "ActsMediaCameraTest.h"
M
mamingshuai 已提交
17
#include "ActsTestMediaUtils.h"
W
wenjun 已提交
18 19

using namespace std;
M
mamingshuai 已提交
20
using namespace OHOS;
W
wenjun 已提交
21 22 23
using namespace OHOS::Media;
using namespace testing::ext;

M
mamingshuai 已提交
24
// SetUpTestCase
W
wenjun 已提交
25 26
void ActsMediaCameraTest::SetUpTestCase(void)
{
M
mamingshuai 已提交
27
    g_testPath = GetCurDir();
W
wenjun 已提交
28 29
    cout << "SetUpTestCase" << endl;
}
M
mamingshuai 已提交
30 31

// TearDownTestCase
W
wenjun 已提交
32 33
void ActsMediaCameraTest::TearDownTestCase(void)
{
M
mamingshuai 已提交
34
    g_testPath = "";
W
wenjun 已提交
35 36
    cout << "TearDownTestCase" << endl;
}
M
mamingshuai 已提交
37

W
wenjun 已提交
38 39
void ActsMediaCameraTest::SetUp(void)
{
M
mamingshuai 已提交
40 41 42 43
    // CameraSetUp
    CameraFlag::g_onGetCameraAbilityFlag = FLAG0;
    CameraFlag::g_onConfigureFlag = FLAG0;
    CameraFlag::g_onGetSupportedSizesFlag = FLAG0;
W
wenjun 已提交
44 45 46 47 48 49
    // CameraDeviceCallBack
    CameraFlag::g_onCameraAvailableFlag = FLAG0;
    CameraFlag::g_onCameraUnavailableFlag = FLAG0;
    // CameraStateCallback
    CameraFlag::g_onCreatedFlag = FLAG0;
    CameraFlag::g_onCreateFailedFlag = FLAG0;
M
mamingshuai 已提交
50 51
    CameraFlag::g_onConfiguredFlag = FLAG0;
    CameraFlag::g_onConfigureFailedFlag = FLAG0;
W
wenjun 已提交
52 53 54 55 56
    CameraFlag::g_onReleasedFlag = FLAG0;
    // FrameStateCallback
    CameraFlag::g_onCaptureTriggerAbortedFlag = FLAG0;
    CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG0;
    CameraFlag::g_onCaptureTriggerStartedFlag = FLAG0;
M
mamingshuai 已提交
57 58
    CameraFlag::g_onFrameFinishedFlag = FLAG0;
    CameraFlag::g_onGetFrameConfigureType = FLAG0;
W
wenjun 已提交
59 60 61 62 63 64
    CameraFlag::g_onFrameErrorFlag = FLAG0;
    CameraFlag::g_onFrameProgressedFlag = FLAG0;
    CameraFlag::g_onFrameStartedFlag = FLAG0;
    cout << "SetUp" << endl;
}

M
mamingshuai 已提交
65
// Tear down
W
wenjun 已提交
66 67
void ActsMediaCameraTest::TearDown(void)
{
M
mamingshuai 已提交
68
    cout << "TearDown." << endl;
W
wenjun 已提交
69 70
}

M
mamingshuai 已提交
71 72 73 74
/* *
 * creat Recorder
 */
Recorder *SampleCreateRecorder()
W
wenjun 已提交
75
{
M
mamingshuai 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    int ret = 0;
    int32_t sampleRate = 48000;
    int32_t channelCount = 1;
    AudioCodecFormat audioFormat = AAC_LC;
    AudioSourceType inputSource = AUDIO_MIC;
    int32_t audioEncodingBitRate = sampleRate;
    VideoSourceType source = VIDEO_SOURCE_SURFACE_ES;
    int32_t frameRate = 30;
    double fps = 30;
    int32_t rate = 4096;
    int32_t sourceId = 0;
    int32_t audioSourceId = 0;
    int32_t width = 1920;
    int32_t height = 1080;
    VideoCodecFormat encoder;
    encoder = HEVC;
    Recorder *recorder = new Recorder();
    if ((ret = recorder->SetVideoSource(source, sourceId)) != SUCCESS) {
        cout << "SetVideoSource failed." << ret << endl;
        delete recorder;
        return nullptr;
W
wenjun 已提交
97
    }
M
mamingshuai 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    if ((ret = recorder->SetVideoEncoder(sourceId, encoder)) != SUCCESS) {
        cout << "SetVideoEncoder failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetVideoSize(sourceId, width, height)) != SUCCESS) {
        cout << "SetVideoSize failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetVideoFrameRate(sourceId, frameRate)) != SUCCESS) {
        cout << "SetVideoFrameRate failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetVideoEncodingBitRate(sourceId, rate)) != SUCCESS) {
        cout << "SetVideoEncodingBitRate failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetCaptureRate(sourceId, fps)) != SUCCESS) {
        cout << "SetCaptureRate failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) {
        cout << "SetAudioSource failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) {
        cout << "SetAudioEncoder failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) {
        cout << "SetAudioSampleRate failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) {
        cout << "SetAudioChannels failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    if ((ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) {
        cout << "SetAudioEncodingBitRate failed." << ret << endl;
        delete recorder;
        return nullptr;
    }
    return recorder;
}
W
wenjun 已提交
150

M
mamingshuai 已提交
151 152 153 154 155
/* *
 * Create Frame StateCallback
 */
class SampleFrameStateCallback : public FrameStateCallback {
    void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
W
wenjun 已提交
156
    {
M
mamingshuai 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        CameraFlag::g_onFrameStartedFlag = FLAG1;
        CameraFlag::g_onFrameProgressedFlag = FLAG1;
        cout << "Receive frame complete inform." << endl;
        if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
            CameraFlag::g_onGetFrameConfigureType = FLAG1;
            cout << "Capture frame received." << endl;
            list<Surface *> surfaceList = fc.GetSurfaces();
            for (Surface *surface : surfaceList) {
                SurfaceBuffer *buffer = surface->AcquireBuffer();
                if (buffer != nullptr) {
                    char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
                    if (virtAddr != nullptr) {
                        SampleSaveCapture(g_testPath, virtAddr, buffer->GetSize());
                    } else {
                        CameraFlag::g_onFrameErrorFlag = FLAG1;
                    }
                    surface->ReleaseBuffer(buffer);
                } else {
                    CameraFlag::g_onFrameErrorFlag = FLAG1;
                }
                delete surface;
            }
            delete &fc;
        } else {
            CameraFlag::g_onFrameErrorFlag = FLAG1;
        }
        CameraFlag::g_onFrameFinishedFlag = FLAG1;
W
wenjun 已提交
184 185 186
    }
};

M
mamingshuai 已提交
187 188 189 190
/* *
 * create CameraStateCallback
 */
class SampleCameraStateMng : public CameraStateCallback {
W
wenjun 已提交
191
public:
M
mamingshuai 已提交
192 193 194 195 196
    SampleCameraStateMng() = delete;

    explicit SampleCameraStateMng(EventHandler &eventHdlr) : eventHandler_(eventHdlr) {}

    ~SampleCameraStateMng()
W
wenjun 已提交
197
    {
M
mamingshuai 已提交
198 199 200
        if (recorder_ != nullptr) {
            recorder_->Release();
            delete recorder_;
W
wenjun 已提交
201
        }
M
mamingshuai 已提交
202 203
        if (cam_ != nullptr) {
            cam_->Release();
W
wenjun 已提交
204 205
        }
    }
M
mamingshuai 已提交
206

W
wenjun 已提交
207 208
    void OnCreated(Camera &c) override
    {
M
mamingshuai 已提交
209 210 211 212 213 214 215 216 217 218
        CameraFlag::g_onCreatedFlag = FLAG1;
        cout << "Sample recv OnCreate camera." << endl;
        auto config = CameraConfig::CreateCameraConfig();
        config->SetFrameStateCallback(&fsCb_, &eventHandler_);
        c.Configure(*config);
        CameraFlag::g_onConfigureFlag = FLAG1;
        cam_ = &c;
    }

    void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
W
wenjun 已提交
219 220
    {
        CameraFlag::g_onCreateFailedFlag = FLAG1;
M
mamingshuai 已提交
221
        cout << "Sample recv OnCreateFailed camera." << endl;
W
wenjun 已提交
222
    }
M
mamingshuai 已提交
223

W
wenjun 已提交
224 225 226
    void OnReleased(Camera &c) override
    {
        CameraFlag::g_onReleasedFlag = FLAG1;
M
mamingshuai 已提交
227
        cout << "Sample recv OnReleased camera." << endl;
W
wenjun 已提交
228 229
    }

M
mamingshuai 已提交
230
    void StartRecord()
W
wenjun 已提交
231
    {
M
mamingshuai 已提交
232 233 234 235
        int ret;
        if (isRecording_) {
            cout << "Camera is already recording." << endl;
            return;
W
wenjun 已提交
236
        }
M
mamingshuai 已提交
237 238 239 240 241 242 243 244 245 246 247 248
        if (recorder_ == nullptr) {
            recorder_ = SampleCreateRecorder();
        }
        if (recorder_ == nullptr) {
            cout << "Recorder not available" << endl;
            return;
        }
        string path = GetCurDir();
        ret = recorder_->SetOutputPath(path);
        if (ret != SUCCESS) {
            cout << "SetOutputPath failed :" << ret << std::endl;
            return;
W
wenjun 已提交
249 250
        }

M
mamingshuai 已提交
251 252 253 254
        ret = recorder_->Prepare();
        if (ret != SUCCESS) {
            cout << "Prepare failed.=" << ret << endl;
            return;
W
wenjun 已提交
255
        }
M
mamingshuai 已提交
256 257 258 259 260 261 262 263 264 265 266
        Surface *surface = (recorder_->GetSurface(0)).get();
        surface->SetWidthAndHeight(WIDTH, HEIGHT);
        surface->SetQueueSize(QUEUE_SIZE);
        surface->SetSize(BUFFER_SIZE * BUFFER_SIZE);
        FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD);
        fc->AddSurface(*surface);
        ret = recorder_->Start();
        if (ret != SUCCESS) {
            delete fc;
            cout << "recorder start failed. ret=" << ret << endl;
            return;
W
wenjun 已提交
267
        }
M
mamingshuai 已提交
268 269 270 271 272 273
        static int cnt = 3;
        while (cam_ == nullptr) {
            if (cnt-- < 0)
                break;
            cout << "Wait camera created success" << endl;
            sleep(1);
W
wenjun 已提交
274
        }
M
mamingshuai 已提交
275 276 277 278 279 280

        ret = cam_->TriggerLoopingCapture(*fc);
        if (ret != 0) {
            delete fc;
            cout << "camera start recording failed. ret=" << ret << endl;
            return;
W
wenjun 已提交
281
        }
M
mamingshuai 已提交
282 283 284 285 286 287 288 289 290
        isRecording_ = true;
        cout << "camera start recording succeed." << endl;
    }

    void StartPreview()
    {
        if (isPreviewing_) {
            cout << "Camera is already previewing." << endl;
            return;
W
wenjun 已提交
291
        }
M
mamingshuai 已提交
292 293 294 295 296 297
        FrameConfig *fc = new FrameConfig(FRAME_CONFIG_PREVIEW);
        Surface *surface = Surface::CreateSurface();
        if (surface == nullptr) {
            delete fc;
            cout << "CreateSurface failed" << endl;
            return;
W
wenjun 已提交
298
        }
M
mamingshuai 已提交
299 300 301 302 303 304 305 306 307 308 309 310
        surface->SetWidthAndHeight(WIDTH, HEIGHT);
        surface->SetUserData("region_position_x", "0");
        surface->SetUserData("region_position_y", "0");
        surface->SetUserData("region_width", "480");
        surface->SetUserData("region_height", "480");
        fc->AddSurface(*surface);
        static int cnt = 3;
        while (cam_ == nullptr) {
            if (cnt-- < 0)
                break;
            cout << "Wait camera created success" << endl;
            sleep(1);
W
wenjun 已提交
311
        }
M
mamingshuai 已提交
312 313 314 315 316
        int32_t ret = cam_->TriggerLoopingCapture(*fc);
        if (ret != 0) {
            delete fc;
            cout << "camera start preview failed. ret=" << ret << endl;
            return;
W
wenjun 已提交
317
        }
M
mamingshuai 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331
        CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG1;
        delete surface;
        isPreviewing_ = true;
        cout << "camera start preview succeed." << endl;
    }

    void Capture()
    {
        FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
        Surface *surface = Surface::CreateSurface();
        if (surface == nullptr) {
            delete fc;
            cout << "CreateSurface failed" << endl;
            return;
W
wenjun 已提交
332
        }
M
mamingshuai 已提交
333 334 335 336 337 338 339 340
        surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
        fc->AddSurface(*surface);
        static int cnt = 3;
        while (cam_ == nullptr) {
            if (cnt-- < 0)
                break;
            cout << "Wait camera created success" << endl;
            sleep(1);
W
wenjun 已提交
341
        }
M
mamingshuai 已提交
342 343 344 345 346 347 348 349 350
        CameraFlag::g_onCaptureTriggerStartedFlag = FLAG1;
        cam_->TriggerSingleCapture(*fc);
        CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG1;
    }

    void Stop()
    {
        if (recorder_ != nullptr) {
            recorder_->Stop(false);
W
wenjun 已提交
351
        }
M
mamingshuai 已提交
352 353 354 355

        while (cam_ == nullptr) {
            cout << "Camera is not ready." << endl;
            return;
W
wenjun 已提交
356
        }
M
mamingshuai 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
        cam_->StopLoopingCapture();
        isPreviewing_ = false;
        isRecording_ = false;
    }

    bool isPreviewing_ = false;
    bool isRecording_ = false;
    EventHandler &eventHandler_;
    Camera *cam_ = nullptr;
    Recorder *recorder_ = nullptr;
    SampleFrameStateCallback fsCb_;
};

/* *
 * create CameraStateCallback for state test
 */
class SampleCameraStateCallback : public CameraStateCallback {
public:
    SampleCameraStateCallback() = delete;

    explicit SampleCameraStateCallback(EventHandler &eventHdlr) : eventHandler_(eventHdlr) {}

    ~SampleCameraStateCallback()
    {
        if (cam_ != nullptr) {
            cam_->Release();
W
wenjun 已提交
383 384 385 386 387 388
        }
    }

    void OnCreated(Camera &c) override
    {
        CameraFlag::g_onCreatedFlag = FLAG1;
M
mamingshuai 已提交
389 390 391 392 393 394 395 396
        cout << "camera Create success." << endl;
        auto config = CameraConfig::CreateCameraConfig();
        config->SetFrameStateCallback(&fsCb_, &eventHandler_);
        c.Configure(*config);
        cam_ = &c;
    }

    void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
W
wenjun 已提交
397 398
    {
        CameraFlag::g_onCreateFailedFlag = FLAG1;
M
mamingshuai 已提交
399
        cout << "Camera Create Failed." << endl;
W
wenjun 已提交
400
    }
M
mamingshuai 已提交
401

W
wenjun 已提交
402 403 404
    void OnReleased(Camera &c) override
    {
        CameraFlag::g_onReleasedFlag = FLAG1;
M
mamingshuai 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417
        cout << "camera Releasedsuccess." << endl;
    }

    void OnConfigured(Camera &c) override
    {
        CameraFlag::g_onConfiguredFlag = FLAG1;
        cout << "Camera Configured success." << endl;
    }

    void OnConfigureFailed(const std::string cameraId, int32_t errorCode) override
    {
        CameraFlag::g_onConfigureFailedFlag = FLAG1;
        cout << "Camera Configured failed." << endl;
W
wenjun 已提交
418 419
    }

M
mamingshuai 已提交
420 421 422
    EventHandler &eventHandler_;
    Camera *cam_ = nullptr;
    SampleFrameStateCallback fsCb_;
W
wenjun 已提交
423
};
M
mamingshuai 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

/* *
 * Creat camera device callback
 */
class SampleCameraDeviceCallback : public CameraDeviceCallback {
public:
    SampleCameraDeviceCallback() {}

    ~SampleCameraDeviceCallback() {}

    // camera device status changed
    void OnCameraStatus(std::string cameraId, int32_t status) override
    {
        cout << "SampleCameraDeviceCallback OnCameraStatus\n" << endl;
        if (status == CAMERA_DEVICE_STATE_AVAILABLE) {
            CameraFlag::g_onCameraAvailableFlag = FLAG1;
            cout << "SampleCameraDeviceCallback onCameraAvailable\n" << endl;
        } else if (status == CAMERA_DEVICE_STATE_UNAVAILABLE) {
            CameraFlag::g_onCameraUnavailableFlag = FLAG1;
            cout << "SampleCameraDeviceCallback onCameraUnavailable\n" << endl;
        }
    }
};

/* *
 * Get camera Id
 */
void GetCameraId(CameraKit *cameraKit, list<string> &camList, string &camId)
{
    cameraKit = CameraKit::GetInstance();
    camList = cameraKit->GetCameraIds();
    for (auto &cam : camList) {
        cout << "camera name:" << cam << endl;
        const CameraAbility *ability = cameraKit->GetCameraAbility(cam);
        EXPECT_NE(ability, nullptr);
        CameraFlag::g_onGetCameraAbilityFlag = FLAG1;
        /* find camera which fits user's ability */
        list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
        if (sizeList.size() != 0) {
            CameraFlag::g_onGetSupportedSizesFlag = FLAG1;
        }
        for (auto &pic : sizeList) {
            cout << "Pic size: " << pic.width << "x" << pic.height << endl;
            if (pic.width == WIDTH && pic.height == HEIGHT) {
                /* 1920:width,1080:height */
                camId = cam;
                break;
            }
        }
    }
    if (camId.empty()) {
        cout << "No available camera.(1080p wanted)" << endl;
        return;
    }
}
W
wenjun 已提交
479 480 481 482

using namespace OHOS;
using namespace std;

M
mamingshuai 已提交
483 484 485 486 487 488
/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0100
 * @tc.name      : Get cameraIDs
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, Test_GetCameraIDs, Function | MediumTest | Level1)
W
wenjun 已提交
489
{
M
mamingshuai 已提交
490 491 492 493 494 495 496 497
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    EXPECT_FALSE(camId.empty());
    EXPECT_EQ("main", camId);
    cameraKit = NULL;
W
wenjun 已提交
498 499 500
}

/* *
M
mamingshuai 已提交
501 502
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0200
 * @tc.name      : Get cameraAbility
W
wenjun 已提交
503 504
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
505
HWTEST_F(ActsMediaCameraTest, Test_GetCameraAbility, Function | MediumTest | Level1)
W
wenjun 已提交
506
{
M
mamingshuai 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    EXPECT_EQ(CameraFlag::g_onGetCameraAbilityFlag, FLAG1);
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0300
 * @tc.name      : CameraKit get instance
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestCreatCamerakit, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    cameraKit = CameraKit::GetInstance();
W
wenjun 已提交
526
    EXPECT_NE(nullptr, cameraKit);
M
mamingshuai 已提交
527
    cameraKit = NULL;
W
wenjun 已提交
528 529 530
}

/* *
M
mamingshuai 已提交
531 532
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0400
 * @tc.name      : Get cameraKit deviceCallback
W
wenjun 已提交
533 534
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
535
HWTEST_F(ActsMediaCameraTest, TestNewDeviceCallback, Function | MediumTest | Level1)
W
wenjun 已提交
536
{
M
mamingshuai 已提交
537 538
    SampleCameraDeviceCallback *deviceCallback = nullptr;
    deviceCallback = new SampleCameraDeviceCallback();
W
wenjun 已提交
539 540
    EXPECT_NE(nullptr, deviceCallback);
    delete deviceCallback;
M
mamingshuai 已提交
541
    deviceCallback = nullptr;
W
wenjun 已提交
542 543 544
}

/* *
M
mamingshuai 已提交
545 546
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0500
 * @tc.name      : Get cameraKit supported Size
W
wenjun 已提交
547 548
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
549
HWTEST_F(ActsMediaCameraTest, TestGetSupportedSizes, Function | MediumTest | Level1)
W
wenjun 已提交
550
{
M
mamingshuai 已提交
551 552 553 554 555 556 557
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    EXPECT_EQ(CameraFlag::g_onGetSupportedSizesFlag, FLAG1);
    cameraKit = NULL;
W
wenjun 已提交
558 559 560
}

/* *
M
mamingshuai 已提交
561 562
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0600
 * @tc.name      : Register Camera device callback
W
wenjun 已提交
563 564
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
565
HWTEST_F(ActsMediaCameraTest, Test_RegisterCameraDeviceCallback, Function | MediumTest | Level1)
W
wenjun 已提交
566
{
M
mamingshuai 已提交
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    SampleCameraDeviceCallback *deviceCallback = nullptr;
    deviceCallback = new SampleCameraDeviceCallback();
    EXPECT_NE(nullptr, deviceCallback);
    cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
    delete deviceCallback;
    deviceCallback = nullptr;
    cameraKit = NULL;
W
wenjun 已提交
582 583 584
}

/* *
M
mamingshuai 已提交
585 586
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0700
 * @tc.name      : Unregister Camera Device Callback
W
wenjun 已提交
587 588
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
589
HWTEST_F(ActsMediaCameraTest, Test_UnregisterCameraDeviceCallback, Function | MediumTest | Level1)
W
wenjun 已提交
590
{
M
mamingshuai 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    SampleCameraDeviceCallback *deviceCallback = nullptr;
    deviceCallback = new SampleCameraDeviceCallback();
    EXPECT_NE(nullptr, deviceCallback);
    cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
    cameraKit->UnregisterCameraDeviceCallback(*deviceCallback);
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onCameraUnavailableFlag, FLAG0);
W
wenjun 已提交
606
    delete deviceCallback;
M
mamingshuai 已提交
607 608
    deviceCallback = nullptr;
    cameraKit = NULL;
W
wenjun 已提交
609 610 611
}

/* *
M
mamingshuai 已提交
612 613
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0800
 * @tc.name      : Capture On Configure
W
wenjun 已提交
614 615
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
616
HWTEST_F(ActsMediaCameraTest, TestCaptureOnConfigure, Function | MediumTest | Level1)
W
wenjun 已提交
617
{
M
mamingshuai 已提交
618 619 620 621 622 623 624 625 626 627 628 629
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(1);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
    EXPECT_NE(camStateMng.cam_, nullptr);
    cameraKit = NULL;
W
wenjun 已提交
630 631 632
}

/* *
M
mamingshuai 已提交
633 634
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_0900
 * @tc.name      : Create Camera
W
wenjun 已提交
635 636
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
637
HWTEST_F(ActsMediaCameraTest, TestCreateCamera, Function | MediumTest | Level1)
W
wenjun 已提交
638
{
M
mamingshuai 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
    EXPECT_NE(CameraFlag::g_onCreateFailedFlag, FLAG1);
    EXPECT_NE(camStateMng.cam_, nullptr);
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1000
 * @tc.name      : Create Camera with error camera id
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestCapture_Create_Camera_ERROR_cameraId, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    cameraKit = CameraKit::GetInstance();
    string camId = "0";
    EventHandler eventHdlr;
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG0);
    EXPECT_EQ(CameraFlag::g_onCreateFailedFlag, FLAG1);
    cameraKit = NULL;
W
wenjun 已提交
672 673 674
}

/* *
M
mamingshuai 已提交
675 676
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1100
 * @tc.name      : Test Capture Frame config
W
wenjun 已提交
677 678
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
679
HWTEST_F(ActsMediaCameraTest, TestCapture_Frame_config, Function | MediumTest | Level1)
W
wenjun 已提交
680
{
M
mamingshuai 已提交
681 682 683 684 685 686 687 688 689 690
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
    EXPECT_NE(fc, nullptr);
W
wenjun 已提交
691
    delete fc;
M
mamingshuai 已提交
692
    cameraKit = NULL;
W
wenjun 已提交
693 694 695
}

/* *
M
mamingshuai 已提交
696 697
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1200
 * @tc.name      : Test Create Surface
W
wenjun 已提交
698 699
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
700
HWTEST_F(ActsMediaCameraTest, TestCapture_Create_Surface, Function | MediumTest | Level1)
W
wenjun 已提交
701
{
M
mamingshuai 已提交
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
    Surface *surface = Surface::CreateSurface();
    if (surface == nullptr) {
        delete fc;
        cout << "CreateSurface failed" << endl;
    }
    EXPECT_NE(surface, nullptr);
    delete surface;
W
wenjun 已提交
719
    delete fc;
M
mamingshuai 已提交
720
    cameraKit = NULL;
W
wenjun 已提交
721 722 723
}

/* *
M
mamingshuai 已提交
724 725
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1300
 * @tc.name      : Get Surface Size
W
wenjun 已提交
726 727
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
728
HWTEST_F(ActsMediaCameraTest, TestCapture_GetSurfaceSize, Function | MediumTest | Level1)
W
wenjun 已提交
729
{
M
mamingshuai 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
    Surface *surface = Surface::CreateSurface();
    if (surface == nullptr) {
        delete fc;
        cout << "CreateSurface failed" << endl;
    }
    surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
    EXPECT_EQ(1920, surface->GetWidth());
    EXPECT_EQ(1080, surface->GetHeight());
    delete surface;
W
wenjun 已提交
749
    delete fc;
M
mamingshuai 已提交
750
    cameraKit = NULL;
W
wenjun 已提交
751 752 753
}

/* *
M
mamingshuai 已提交
754 755
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1400
 * @tc.name      : Get FrameConfig size
W
wenjun 已提交
756 757
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
758
HWTEST_F(ActsMediaCameraTest, TestCapture_frameConfig_getsize, Function | MediumTest | Level1)
W
wenjun 已提交
759
{
M
mamingshuai 已提交
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
    Surface *surface = Surface::CreateSurface();
    if (surface == nullptr) {
        delete fc;
        cout << "CreateSurface failed" << endl;
    }
    surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
    fc->AddSurface(*surface);
    EXPECT_NE(0, fc->GetSurfaces().size());
    delete surface;
W
wenjun 已提交
779
    delete fc;
M
mamingshuai 已提交
780
    cameraKit = NULL;
W
wenjun 已提交
781 782 783
}

/* *
M
mamingshuai 已提交
784 785
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1500
 * @tc.name      : Test Get Frame
W
wenjun 已提交
786 787
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
788
HWTEST_F(ActsMediaCameraTest, TestOnFrameProgressed, Function | MediumTest | Level1)
W
wenjun 已提交
789
{
M
mamingshuai 已提交
790 791 792 793 794 795 796 797 798 799 800 801 802 803
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    camStateMng.Capture();
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onFrameStartedFlag, FLAG1);
    EXPECT_EQ(CameraFlag::g_onFrameProgressedFlag, FLAG1);
    cameraKit = NULL;
W
wenjun 已提交
804 805 806
}

/* *
M
mamingshuai 已提交
807 808
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1600
 * @tc.name      : Get FrameConfig onConfig
W
wenjun 已提交
809 810
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
811
HWTEST_F(ActsMediaCameraTest, TestGetFrameConfigureType, Function | MediumTest | Level1)
W
wenjun 已提交
812
{
M
mamingshuai 已提交
813 814 815 816 817 818 819 820 821 822 823 824 825
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    camStateMng.Capture();
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onGetFrameConfigureType, FLAG1);
    cameraKit = NULL;
W
wenjun 已提交
826 827 828
}

/* *
M
mamingshuai 已提交
829 830
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1700
 * @tc.name      : Test Get Frame finished
W
wenjun 已提交
831 832
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
833
HWTEST_F(ActsMediaCameraTest, TestFrameCompletedFlag, Function | MediumTest | Level1)
W
wenjun 已提交
834
{
M
mamingshuai 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    camStateMng.Capture();
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onFrameFinishedFlag, FLAG1);
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1800
 * @tc.name      : Test GetFrame Error
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestonFrameErrorFlag, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    camStateMng.Capture();
    sleep(1);
    EXPECT_NE(CameraFlag::g_onFrameErrorFlag, FLAG1);
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_1900
 * @tc.name      : Test Capture Success
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestCapture01, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    camStateMng.Capture();
    sleep(1);
    EXPECT_EQ(CameraFlag::g_onCaptureTriggerStartedFlag, FLAG1);
    EXPECT_EQ(CameraFlag::g_onCaptureTriggerCompletedFlag, FLAG1);
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_2000
 * @tc.name      : Test capture and record
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestRecord01, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
    EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
    camStateMng.Capture();
    sleep(3);
    camStateMng.StartRecord();
    sleep(3);
    camStateMng.Stop();
    cameraKit = NULL;
}

/* *
 * @tc.number    : SUB_MEDIA_CAMERA_DEV_2100
 * @tc.name      : Test get event handler
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(ActsMediaCameraTest, TestGetEventHandler, Function | MediumTest | Level1)
{
    CameraKit *cameraKit = nullptr;
    list<string> camList;
    string camId;
    EventHandler eventHdlr;
    GetCameraId(cameraKit, camList, camId);
    SampleCameraStateMng camStateMng(eventHdlr);
    sleep(3);
    cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
    sleep(3);
    EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
    EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
    camStateMng.Capture();
    sleep(3);
    camStateMng.StartRecord();
    sleep(3);
    camStateMng.Stop();
    cameraKit = NULL;
W
wenjun 已提交
945
}