diff --git a/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn b/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn index 3f4685ab53a52948464405265f1a7a4813c8d1c7..b17c18fc0a5dfb4560fee42d235e2010ce58f078 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/test/sample/BUILD.gn @@ -18,8 +18,6 @@ import( config("module_private_config") { include_dirs = [ - "//base/security/access_token/interfaces/innerkits/nativetoken/include", - "//base/security/access_token/interfaces/innerkits/token_setproc/include", "//drivers/peripheral/camera/interfaces/metadata/include", "//third_party/jsoncpp/include", "//commonlibrary/c_utils/base/include", @@ -72,13 +70,14 @@ ohos_executable("dcamera_client_demo") { "${graphicstandard_path}:libsurface", "${services_path}/cameraservice/cameraoperator/client:distributed_camera_client", "${services_path}/cameraservice/sinkservice:distributed_camera_sink", - "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", - "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//third_party/jsoncpp:jsoncpp", ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "hiviewdfx_hilog_native:libhilog", diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index 277a0a2205321ea00d7e8ca516d2ba50cac22ad9..df39e65abdb4bf564afa49c8ba8bcb7555edb1bc 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -15,6 +15,7 @@ #include "dcamera_client_demo.h" +#include "accesstoken_kit.h" #include "nativetoken_kit.h" #include "token_setproc.h" @@ -214,6 +215,7 @@ int main() }; tokenId = GetAccessTokenId(&infoInstance); SetSelfTokenID(tokenId); + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); DHLOGI("========== Distributed Camera Demo Start =========="); int32_t ret = InitCameraStandard(); diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn index dc079ca8f347ae3ca926673f4950db067ae8ce4c..687b221114bbc123c1a01b125a576303fbacb60f 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/BUILD.gn @@ -68,6 +68,9 @@ ohos_unittest("DCameraClientTest") { ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "eventhandler:libeventhandler", diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp index ca5b8abae9673350fcce92756f013515403ac077..30e0460192480196b30775ec0f2cbc4750973a16 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp @@ -15,12 +15,15 @@ #include +#include "accesstoken_kit.h" #include "anonymous_string.h" #include "dcamera_client.h" #include "dcamera_handler.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" using namespace testing::ext; @@ -57,6 +60,7 @@ const int32_t TEST_WIDTH = 1920; const int32_t TEST_HEIGHT = 1080; const int32_t TEST_FORMAT_3 = 3; const int32_t TEST_FORMAT_4 = 4; +const int32_t TEST_SLEEP_SEC = 2; class DCameraClientTest : public testing::Test { public: @@ -64,6 +68,7 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + void SetTokenID(); std::shared_ptr client_; std::shared_ptr photoInfo_false_; @@ -128,6 +133,27 @@ void DCameraClientTest::TearDown(void) videoInfo_true_ = nullptr; } +void DCameraClientTest::SetTokenID() +{ + uint64_t tokenId; + const char *perms[2]; + perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; + perms[1] = "ohos.permission.CAMERA"; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 2, + .aclsNum = 0, + .dcaps = NULL, + .perms = perms, + .acls = NULL, + .processName = "dcamera_client_demo", + .aplStr = "system_basic", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} + /** * @tc.name: dcamera_client_test_001 * @tc.desc: Verify SetStateCallback @@ -200,6 +226,16 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); + SetTokenID(); + DHLOGI("DCameraClientTest dcamera_client_test_004: video width: %d, height: %d, format: %d, isCapture: %d", + videoInfo_true_->width_, videoInfo_true_->height_, videoInfo_true_->format_, videoInfo_true_->isCapture_); + std::vector> captureInfos; + captureInfos.push_back(videoInfo_true_); + ret = client_->StartCapture(captureInfos); + EXPECT_EQ(DCAMERA_OK, ret); + + sleep(TEST_SLEEP_SEC); + ret = client_->StopCapture(); EXPECT_EQ(DCAMERA_OK, ret); @@ -227,6 +263,30 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); + SetTokenID(); + DHLOGI("DCameraClientTest dcamera_client_test_005: video width: %d, height: %d, format: %d, isCapture: %d", + videoInfo_true_->width_, videoInfo_true_->height_, videoInfo_true_->format_, videoInfo_true_->isCapture_); + DHLOGI("DCameraClientTest dcamera_client_test_005: photo width: %d, height: %d, format: %d, isCapture: %d", + photoInfo_false_->width_, photoInfo_false_->height_, photoInfo_false_->format_, photoInfo_false_->isCapture_); + std::vector> captureInfos; + captureInfos.push_back(videoInfo_true_); + captureInfos.push_back(photoInfo_false_); + ret = client_->StartCapture(captureInfos); + EXPECT_EQ(DCAMERA_OK, ret); + + sleep(TEST_SLEEP_SEC); + + DHLOGI("DCameraClientTest dcamera_client_test_005: video width: %d, height: %d, format: %d, isCapture: %d", + videoInfo_false_->width_, videoInfo_false_->height_, videoInfo_false_->format_, videoInfo_false_->isCapture_); + DHLOGI("DCameraClientTest dcamera_client_test_005: photo width: %d, height: %d, format: %d, isCapture: %d", + photoInfo_true_->width_, photoInfo_true_->height_, photoInfo_true_->format_, photoInfo_true_->isCapture_); + captureInfos.clear(); + captureInfos.push_back(videoInfo_false_); + captureInfos.push_back(photoInfo_true_); + ret = client_->StartCapture(captureInfos); + EXPECT_EQ(DCAMERA_OK, ret); + + sleep(TEST_SLEEP_SEC); ret = client_->StopCapture(); EXPECT_EQ(DCAMERA_OK, ret);