RDK Documentation (Open Sourced RDK Components)
opencdmMocks.cpp
1 #include <string.h>
2 
3 #include "open_cdm.h"
4 #include "open_cdm_adapter.h"
5 #include <gst/gst.h>
6 
7 #include "opencdmMocks.h"
8 
9 #include "CppUTestExt/MockSupport.h"
10 
12 {
13  MockOpenCdmSessionInfo sessionInfo;
14  MockOpenCdmCallbacks callbacks;
15  void *mockUserData; // User data from the client of the mock
17 
18 static MockOpenCdmInstanceData f_mockInstance;
19 
20 /* BEGIN - methods to access mock functionality */
21 MockOpenCdmSessionInfo* MockOpenCdmGetSessionInfo()
22 {
23  return &f_mockInstance.sessionInfo;
24 }
25 
26 void MockOpenCdmSetCallbacks(MockOpenCdmCallbacks callbacks, void *mockUserData)
27 {
28  f_mockInstance.callbacks = callbacks;
29  f_mockInstance.mockUserData = mockUserData;
30 }
31 
32 void MockOpenCdmReset(void)
33 {
34  memset(&f_mockInstance, 0, sizeof(f_mockInstance));
35 }
36 /* END - methods to access mock functionality */
37 
38 struct OpenCDMSystem* opencdm_create_system(const char keySystem[])
39 {
40  return (OpenCDMSystem *)mock("OpenCDM").actualCall("opencdm_create_system")
41  .withParameter("keySystem", keySystem)
42  .returnPointerValueOrDefault(0);
43 }
44 
45 OpenCDMError opencdm_construct_session(struct OpenCDMSystem* system,
46  const LicenseType licenseType, const char initDataType[],
47  const uint8_t initData[], const uint16_t initDataLength,
48  const uint8_t CDMData[], const uint16_t CDMDataLength,
49  OpenCDMSessionCallbacks* callbacks, void* userData,
50  struct OpenCDMSession** session)
51 {
52  OpenCDMError retValue = (OpenCDMError)mock("OpenCDM").actualCall("opencdm_construct_session")
53  .withOutputParameter("session", session)
54  .returnIntValueOrDefault(ERROR_NONE);
55 
56  f_mockInstance.sessionInfo.session = *session;
57  f_mockInstance.sessionInfo.callbacks = *callbacks;
58  f_mockInstance.sessionInfo.userData = userData;
59 
60  if (f_mockInstance.callbacks.constructSessionCallback)
61  {
62  f_mockInstance.callbacks.constructSessionCallback(&f_mockInstance.sessionInfo, f_mockInstance.mockUserData);
63  }
64 
65  return retValue;
66 }
67 
68 OpenCDMError opencdm_destruct_system(struct OpenCDMSystem* system)
69 {
70  return ERROR_NONE;
71 }
72 
73 KeyStatus opencdm_session_status(const struct OpenCDMSession* session,
74  const uint8_t keyId[], const uint8_t length)
75 {
76  return Usable;
77 }
78 
79 OpenCDMError opencdm_session_update(struct OpenCDMSession* session,
80  const uint8_t keyMessage[],
81  const uint16_t keyLength)
82 {
83  OpenCDMError retValue = (OpenCDMError)mock("OpenCDM").actualCall("opencdm_session_update")
84  .withMemoryBufferParameter("keyMessage", keyMessage, (size_t)keyLength)
85  .withIntParameter("keyLength", keyLength)
86  .returnIntValueOrDefault(ERROR_NONE);
87 
88  if (f_mockInstance.callbacks.sessionUpdateCallback)
89  {
90  f_mockInstance.callbacks.sessionUpdateCallback(&f_mockInstance.sessionInfo, keyMessage, keyLength);
91  }
92 
93  return retValue;
94 }
95 
96 OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, GstBuffer* buffer,
97  GstBuffer* subSample, const uint32_t subSampleCount,
98  GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15)
99 {
100  return ERROR_NONE;
101 }
102 
103 OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session,
104  uint8_t encrypted[],
105  const uint32_t encryptedLength,
106  const uint8_t* IV, uint16_t IVLength,
107  const uint8_t* keyId, const uint16_t keyIdLength,
108  uint32_t initWithLast15)
109 {
110  return (OpenCDMError)mock("OpenCDM").actualCall("opencdm_session_decrypt")
111  .withPointerParameter("session", session)
112  .withMemoryBufferParameter("encrypted", encrypted, encryptedLength)
113  .withOutputParameter("encrypted", encrypted)
114  .withIntParameter("encryptedLength", encryptedLength)
115  .withPointerParameter("iv", (void*)IV)
116  .withIntParameter("ivLength", IVLength)
117  .withMemoryBufferParameter("keyId", keyId, keyIdLength)
118  .withIntParameter("keyIdLength", keyIdLength)
119  .returnIntValueOrDefault(ERROR_NONE);
120 }
121 
122 OpenCDMError opencdm_session_close(struct OpenCDMSession* session)
123 {
124  return ERROR_NONE;
125 }
126 
127 OpenCDMError opencdm_destruct_session(struct OpenCDMSession* session)
128 {
129  return ERROR_NONE;
130 }
_MockSessionInfo
Definition: opencdmMocks.h:6
_MockOpenCdmCallbacks
Definition: opencdmMocks.h:16
_MockOpenCdmInstanceData
Definition: opencdmMocks.cpp:11