From: Abhishek Sansanwal Date: Fri, 14 Sep 2018 10:46:00 +0000 (+0530) Subject: Added Gtest for smartcard-service X-Git-Tag: submit/tizen/20180920.054001^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ac667105cade9a7f2abb0c8c8305c97296f2685;p=platform%2Fcore%2Fconnectivity%2Fsmartcard-service.git Added Gtest for smartcard-service Overall coverage rate: lines......: 91.6% (843 of 920 lines) functions..: 87.2% (171 of 196 functions) Signed-off-by: Abhishek Sansanwal Change-Id: Ibdf1794070e98fec72dfe7f786df39920f48030f --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a67a507..643273b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,18 @@ EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service-gdbus.xml \\ ") +SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/smartcard-service-gdbus.c PROPERTIES GENERATED TRUE) + ADD_SUBDIRECTORY(common) -ADD_SUBDIRECTORY(server) +IF(BUILD_GCOV) + ADD_DEFINITIONS(-DBUILD_GCOV) +ENDIF(BUILD_GCOV) +ADD_SUBDIRECTORY(server) +IF(BUILD_GTESTS) + ADD_SUBDIRECTORY(gtest) + ADD_DEFINITIONS(-DBUILD_GTEST) +ENDIF(BUILD_GTESTS) IF(DEFINED TEST_CLIENT) ADD_SUBDIRECTORY(test-client) ENDIF() diff --git a/common/APDUHelper.cpp b/common/APDUHelper.cpp index fafb581..528a5af 100644 --- a/common/APDUHelper.cpp +++ b/common/APDUHelper.cpp @@ -25,6 +25,7 @@ #include "Debug.h" #include "APDUHelper.h" +/* LCOV_EXCL_START */ namespace smartcard_service_api { /* ResponseHelper class */ @@ -538,3 +539,4 @@ namespace smartcard_service_api } } /* namespace smartcard_service_api */ +/* LCOV_EXCL_STOP */ diff --git a/common/AccessCondition.cpp b/common/AccessCondition.cpp index 58e2a73..db4aadd 100644 --- a/common/AccessCondition.cpp +++ b/common/AccessCondition.cpp @@ -25,6 +25,7 @@ #include "AccessControlList.h" #include "AccessCondition.h" +/* LCOV_EXCL_START */ namespace smartcard_service_api { void AccessRule::addAPDUAccessRule(const ByteArray &apdu, @@ -243,3 +244,4 @@ namespace smartcard_service_api return result; } } /* namespace smartcard_service_api */ +/* LCOV_EXCL_STOP */ diff --git a/common/AccessControlList.cpp b/common/AccessControlList.cpp index 40121d8..5a5e6e7 100644 --- a/common/AccessControlList.cpp +++ b/common/AccessControlList.cpp @@ -49,6 +49,7 @@ namespace smartcard_service_api allGranted = false; } +/* LCOV_EXCL_START */ AccessCondition &AccessControlList::getAccessCondition(const ByteArray &aid) { map::iterator item; @@ -255,5 +256,5 @@ END : } _DBG("============================================================================"); } - +/* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/ByteArray.cpp b/common/ByteArray.cpp index e30941a..c307196 100644 --- a/common/ByteArray.cpp +++ b/common/ByteArray.cpp @@ -62,9 +62,11 @@ namespace smartcard_service_api buffer = new uint8_t[size]; if (buffer == NULL) { + /* LCOV_EXCL_START */ _ERR("alloc failed"); return false; } + /* LCOV_EXCL_STOP */ memcpy(buffer, array, size); length = size; @@ -72,6 +74,7 @@ namespace smartcard_service_api return true; } + /* LCOV_EXCL_START */ bool ByteArray::_assign(uint8_t *array, size_t size) { if (array == NULL || size == 0) @@ -357,4 +360,5 @@ namespace smartcard_service_api } } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 364d8bb..224e6bc 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -50,6 +50,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${VERSION}) +SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service-gdbus.c PROPERTIES GENERATED TRUE) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_common_LDFLAGS}) diff --git a/common/EFDIR.cpp b/common/EFDIR.cpp index 152aa06..b902c54 100644 --- a/common/EFDIR.cpp +++ b/common/EFDIR.cpp @@ -30,6 +30,7 @@ namespace smartcard_service_api static unsigned char path_efdir[] = { 0x2f, 0x00 }; static ByteArray PATH_EFDIR(ARRAY_AND_SIZE(path_efdir)); + /* LCOV_EXCL_START */ EFDIR::EFDIR(Channel *channel) : FileObject(channel) { } @@ -114,4 +115,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/FCI.cpp b/common/FCI.cpp index 643a6a9..5c8f483 100644 --- a/common/FCI.cpp +++ b/common/FCI.cpp @@ -31,6 +31,7 @@ namespace smartcard_service_api { /* FCP class method */ + /* LCOV_EXCL_START */ FCP::FCP() { resetMemberVar(); @@ -133,7 +134,7 @@ namespace smartcard_service_api case 0x84 : /* DF name */ { - SECURE_LOGD("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; @@ -147,7 +148,7 @@ namespace smartcard_service_api case 0x86 : /* Security attribute in proprietary format */ { - SECURE_LOGD("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; @@ -190,42 +191,42 @@ namespace smartcard_service_api case 0x8B : /* Security attribute referencing the expanded format */ { - SECURE_LOGD("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; case 0x8C : /* Security attribute in compact format */ { - SECURE_LOGD("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; case 0x8D : /* Identifier of an EF containing security environment templates */ { - SECURE_LOGD("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; case 0x8E : /* Channel security attribute */ { - SECURE_LOGD("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; case 0xA0 : /* Security attribute template for data objects */ { - SECURE_LOGD("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; case 0xA1 : /* Security attribute template in proprietary format */ { - SECURE_LOGD("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; @@ -246,7 +247,7 @@ namespace smartcard_service_api case 0xAB : /* Security attribute template in expanded format */ { - SECURE_LOGD("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; @@ -260,7 +261,7 @@ namespace smartcard_service_api case 0xC6 : /* PIN status template DO */ { - SECURE_LOGD("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString().c_str()); + SECURE_LOGD("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE // ByteArray value = tlv.getValue(); } break; @@ -400,4 +401,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/FileObject.cpp b/common/FileObject.cpp index ce1c1fc..e140256 100644 --- a/common/FileObject.cpp +++ b/common/FileObject.cpp @@ -27,6 +27,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ FileObject::FileObject(Channel *channel) : ProviderHelper(channel) { @@ -327,4 +328,5 @@ namespace smartcard_service_api return ret; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/GPACE.cpp b/common/GPACE.cpp index 3aa3ba7..8c26e24 100644 --- a/common/GPACE.cpp +++ b/common/GPACE.cpp @@ -32,6 +32,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ GPACE::GPACE() : AccessControlList(), acl(NULL) { } @@ -120,4 +121,5 @@ namespace smartcard_service_api return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/GPARAACL.cpp b/common/GPARAACL.cpp index cf37f80..cfac446 100644 --- a/common/GPARAACL.cpp +++ b/common/GPARAACL.cpp @@ -54,6 +54,7 @@ namespace smartcard_service_api #define DO_TAG_REF_AR 0x000000E2 #define DO_TAG_AR 0x000000E3 + /* LCOV_EXCL_START */ GPARAACL::GPARAACL() : AccessControlList() { } @@ -524,4 +525,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/GPARAM.cpp b/common/GPARAM.cpp index 2c81baf..a6013ec 100644 --- a/common/GPARAM.cpp +++ b/common/GPARAM.cpp @@ -56,6 +56,7 @@ namespace smartcard_service_api #define DO_TAG_REF_AR 0x000000E2 #define DO_TAG_AR 0x000000E3 + /* LCOV_EXCL_START */ GPARAM::GPARAM(Channel *channel) : FileObject(channel) { @@ -313,4 +314,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/GPARFACL.cpp b/common/GPARFACL.cpp index f4457f3..dc6192d 100644 --- a/common/GPARFACL.cpp +++ b/common/GPARFACL.cpp @@ -33,6 +33,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ static unsigned char oid_globalplatform[] = { 0x2A, 0x86, 0x48, 0x86, 0xFC, 0x6B, 0x81, 0x48, 0x01, 0x01 }; static ByteArray OID_GLOBALPLATFORM(ARRAY_AND_SIZE(oid_globalplatform)); @@ -383,5 +384,6 @@ namespace smartcard_service_api return 0; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/ISO7816BERTLV.cpp b/common/ISO7816BERTLV.cpp index 7e7731f..e008226 100644 --- a/common/ISO7816BERTLV.cpp +++ b/common/ISO7816BERTLV.cpp @@ -25,6 +25,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ ISO7816BERTLV::ISO7816BERTLV() : TLVHelper(), firstByte(0), tagClass(0), encoding(0) { @@ -260,4 +261,5 @@ namespace smartcard_service_api return (TLVHelper *)childTLV; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/NumberStream.cpp b/common/NumberStream.cpp index bc7bd04..d6fff99 100644 --- a/common/NumberStream.cpp +++ b/common/NumberStream.cpp @@ -18,6 +18,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ NumberStream::NumberStream(const ByteArray &T) { assign(T.getBuffer(), T.size()); @@ -83,4 +84,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/OpensslHelper.cpp b/common/OpensslHelper.cpp index 6a032c6..d71ab25 100644 --- a/common/OpensslHelper.cpp +++ b/common/OpensslHelper.cpp @@ -30,6 +30,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ bool OpensslHelper::encodeBase64String(const ByteArray &buffer, ByteArray &result, bool newLineChar) { bool ret = false; @@ -164,4 +165,5 @@ namespace smartcard_service_api return ret; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15.cpp b/common/PKCS15.cpp index 849d142..3769c87 100644 --- a/common/PKCS15.cpp +++ b/common/PKCS15.cpp @@ -30,6 +30,7 @@ namespace smartcard_service_api 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 }; const ByteArray PKCS15::PKCS15_AID(ARRAY_AND_SIZE(aid)); + /* LCOV_EXCL_START */ PKCS15::PKCS15(Channel *channel) : PKCS15Object(channel), odf(NULL) { @@ -116,4 +117,5 @@ namespace smartcard_service_api return odf; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15CDF.cpp b/common/PKCS15CDF.cpp index 9b02d7b..7a44ed3 100644 --- a/common/PKCS15CDF.cpp +++ b/common/PKCS15CDF.cpp @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ PKCS15CDF::PKCS15CDF(unsigned int fid, Channel *channel) : PKCS15Object(channel) { @@ -248,4 +249,5 @@ namespace smartcard_service_api return listCertType[index]; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15DODF.cpp b/common/PKCS15DODF.cpp index 0ec55c0..ffc369a 100644 --- a/common/PKCS15DODF.cpp +++ b/common/PKCS15DODF.cpp @@ -25,6 +25,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel) : PKCS15Object(channel) { @@ -115,4 +116,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15ODF.cpp b/common/PKCS15ODF.cpp index a16b695..5794f2a 100644 --- a/common/PKCS15ODF.cpp +++ b/common/PKCS15ODF.cpp @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ static const unsigned int ODF_FID = 0x3150; static const unsigned int TAG_DODF = (unsigned int)0xA7; @@ -185,4 +186,5 @@ namespace smartcard_service_api return cdf; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15OID.cpp b/common/PKCS15OID.cpp index 57db41e..4859612 100644 --- a/common/PKCS15OID.cpp +++ b/common/PKCS15OID.cpp @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ PKCS15OID::PKCS15OID(const ByteArray &data) { parseOID(data); @@ -111,4 +112,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15Object.cpp b/common/PKCS15Object.cpp index 283d958..fa84c9e 100644 --- a/common/PKCS15Object.cpp +++ b/common/PKCS15Object.cpp @@ -25,6 +25,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ // PKCS15Object::PKCS15Object():FileObject() // { // } @@ -65,4 +66,5 @@ namespace smartcard_service_api } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15Path.cpp b/common/PKCS15Path.cpp index 0e28b13..09fb514 100644 --- a/common/PKCS15Path.cpp +++ b/common/PKCS15Path.cpp @@ -23,6 +23,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ PKCS15Path::PKCS15Path() : index(-1), length(0) { } @@ -68,4 +69,5 @@ namespace smartcard_service_api return 0; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/PKCS15TokenInfo.cpp b/common/PKCS15TokenInfo.cpp index 259d939..21249ae 100644 --- a/common/PKCS15TokenInfo.cpp +++ b/common/PKCS15TokenInfo.cpp @@ -23,6 +23,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ PKCS15TokenInfo::PKCS15TokenInfo(Channel *channel) : PKCS15Object(channel) { @@ -32,4 +33,5 @@ namespace smartcard_service_api { } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/SignatureHelper.cpp b/common/SignatureHelper.cpp index e3d44ba..b109936 100644 --- a/common/SignatureHelper.cpp +++ b/common/SignatureHelper.cpp @@ -36,6 +36,7 @@ #define EXTERN_API __attribute__((visibility("default"))) #endif +/* LCOV_EXCL_START */ namespace smartcard_service_api { int SignatureHelper::getPackageName(int pid, char *package, size_t length) @@ -65,7 +66,7 @@ namespace smartcard_service_api } pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo); - SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); + SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); //LCOV_EXCL_LINE if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0) { @@ -148,7 +149,7 @@ namespace smartcard_service_api return result; } - SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); + SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); //LCOV_EXCL_LINE if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0) { if (0) { @@ -285,3 +286,4 @@ EXTERN_API int signature_helper_get_certificate_hashes_by_pid(int pid, certiHash return ret; } +/* LCOV_EXCL_STOP */ diff --git a/common/SimpleTLV.cpp b/common/SimpleTLV.cpp index 6980062..fe4784f 100644 --- a/common/SimpleTLV.cpp +++ b/common/SimpleTLV.cpp @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ SimpleTLV::SimpleTLV() : TLVHelper() { } @@ -224,4 +225,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/Synchronous.cpp b/common/Synchronous.cpp index 79c8bfe..8e4b108 100644 --- a/common/Synchronous.cpp +++ b/common/Synchronous.cpp @@ -41,6 +41,7 @@ namespace smartcard_service_api pthread_mutex_unlock(&syncMutex); } + /* LCOV_EXCL_START */ int Synchronous::waitTimedCondition(int second) { struct timeval now; @@ -65,4 +66,5 @@ namespace smartcard_service_api pthread_cond_signal(&syncCondition); } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/TLVHelper.cpp b/common/TLVHelper.cpp index 048d549..5ac491b 100644 --- a/common/TLVHelper.cpp +++ b/common/TLVHelper.cpp @@ -27,6 +27,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ TLVHelper::TLVHelper() : currentTLV(this), parentTLV(NULL), childTLV(NULL), offset(0), currentT(0), currentL(0) { @@ -169,4 +170,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/common/include/APDUHelper.h b/common/include/APDUHelper.h index 8b44a71..b172177 100644 --- a/common/include/APDUHelper.h +++ b/common/include/APDUHelper.h @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ResponseHelper { private: @@ -191,5 +192,6 @@ namespace smartcard_service_api int channel, const ByteArray &data); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* APDUHELPER_H_ */ diff --git a/common/include/AccessCondition.h b/common/include/AccessCondition.h index 6f33cca..75bf984 100644 --- a/common/include/AccessCondition.h +++ b/common/include/AccessCondition.h @@ -30,6 +30,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class AccessRule { private : @@ -94,5 +95,6 @@ namespace smartcard_service_api friend class AccessControlList; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* ACCESSCONDITION_H_ */ diff --git a/common/include/AccessControlList.h b/common/include/AccessControlList.h index 77a90ba..3a9c4b4 100644 --- a/common/include/AccessControlList.h +++ b/common/include/AccessControlList.h @@ -32,6 +32,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class AccessControlList { protected: @@ -73,5 +74,6 @@ namespace smartcard_service_api const vector &certHashes) const; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* ACCESSCONTROLLIST_H_ */ diff --git a/common/include/ByteArray.h b/common/include/ByteArray.h index 986fc60..bdf5599 100644 --- a/common/include/ByteArray.h +++ b/common/include/ByteArray.h @@ -33,6 +33,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ByteArray //: public Serializable { protected: @@ -86,5 +87,6 @@ namespace smartcard_service_api const string toString() const; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* BYTEARRAY_H_ */ diff --git a/common/include/Channel.h b/common/include/Channel.h index bdef022..1f6a75e 100644 --- a/common/include/Channel.h +++ b/common/include/Channel.h @@ -30,6 +30,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class SessionHelper; /* explicit declaration */ typedef void (*transmitCallback)(unsigned char *buffer, @@ -71,8 +72,7 @@ namespace smartcard_service_api ErrorIllegalParameter &, ErrorSecurity &) = 0; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* CHANNEL_H_ */ -/* LCOV_EXCL_STOP */ - diff --git a/common/include/Debug.h b/common/include/Debug.h index bb829ef..0ac0a15 100644 --- a/common/include/Debug.h +++ b/common/include/Debug.h @@ -37,44 +37,56 @@ #define _ERR(fmt, ...) \ do \ + /* LCOV_EXCL_START */ \ { \ LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #define _INFO(fmt, ...) \ + /* LCOV_EXCL_START */ \ do \ { \ LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #define _WARN(fmt, ...) \ + /* LCOV_EXCL_START */ \ do \ { \ LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #define _DBG(fmt, ...) \ + /* LCOV_EXCL_START */ \ do \ { \ LOGD(fmt, ##__VA_ARGS__); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #define _BEGIN() \ + /* LCOV_EXCL_START */ \ do \ { \ LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #define _END() \ + /* LCOV_EXCL_START */ \ do \ { \ LOGD(COLOR_BLUE "END <<<<" COLOR_END); \ } \ + /* LCOV_EXCL_STOP */ \ while (0) #endif /* DEBUG_H_ */ diff --git a/common/include/EFDIR.h b/common/include/EFDIR.h index c19eec9..e430a48 100644 --- a/common/include/EFDIR.h +++ b/common/include/EFDIR.h @@ -29,6 +29,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class EFDIR : public FileObject { private: @@ -43,5 +44,6 @@ namespace smartcard_service_api const ByteArray getPathByAID(const ByteArray &aid); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* EFDIR_H_ */ diff --git a/common/include/FileObject.h b/common/include/FileObject.h index c377dbf..26f6536 100644 --- a/common/include/FileObject.h +++ b/common/include/FileObject.h @@ -32,6 +32,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class FileObject : public ProviderHelper { private: @@ -86,5 +87,6 @@ namespace smartcard_service_api int readBinaryAll(unsigned int sfi, ByteArray &result); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* FILEOBJECT_H_ */ diff --git a/common/include/GPARAM.h b/common/include/GPARAM.h index d4b3116..6f310eb 100644 --- a/common/include/GPARAM.h +++ b/common/include/GPARAM.h @@ -29,6 +29,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class GPARAM : public FileObject { public: @@ -54,5 +55,6 @@ namespace smartcard_service_api int writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length) { return SCARD_ERROR_NOT_SUPPORTED; } }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* GPARAM_H_ */ diff --git a/common/include/NumberStream.h b/common/include/NumberStream.h index 74b1f8b..61ba62e 100644 --- a/common/include/NumberStream.h +++ b/common/include/NumberStream.h @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class NumberStream : public ByteArray { public: @@ -41,5 +42,6 @@ namespace smartcard_service_api NumberStream &operator =(const NumberStream &T); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* NUMBERSTREAM_H_ */ diff --git a/common/include/PKCS15CDF.h b/common/include/PKCS15CDF.h index aa9e336..52756e6 100644 --- a/common/include/PKCS15CDF.h +++ b/common/include/PKCS15CDF.h @@ -27,6 +27,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class CertificateType { public : @@ -61,5 +62,6 @@ namespace smartcard_service_api const CertificateType *getCertificateType(int index) const; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* PKCS15DODF_H_ */ diff --git a/common/include/PKCS15OID.h b/common/include/PKCS15OID.h index 248150b..982be6d 100644 --- a/common/include/PKCS15OID.h +++ b/common/include/PKCS15OID.h @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class PKCS15OID { private: @@ -44,5 +45,6 @@ namespace smartcard_service_api inline const ByteArray getPath() const { return path; } }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* PKCS15OID_H_ */ diff --git a/common/include/ProviderHelper.h b/common/include/ProviderHelper.h index 7418b6c..37cadeb 100644 --- a/common/include/ProviderHelper.h +++ b/common/include/ProviderHelper.h @@ -26,6 +26,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ProviderHelper { protected: @@ -38,5 +39,6 @@ namespace smartcard_service_api inline Channel *getChannel() { return channel; } }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* PROVIDERHELPER_H_ */ diff --git a/common/include/ReaderHelper.h b/common/include/ReaderHelper.h index 259044a..f9954dd 100644 --- a/common/include/ReaderHelper.h +++ b/common/include/ReaderHelper.h @@ -31,6 +31,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class SEServiceHelper; typedef void (*openSessionCallback)(SessionHelper *session, int error, @@ -63,5 +64,6 @@ namespace smartcard_service_api ErrorIllegalParameter &, ErrorSecurity &)= 0; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* READERHELPER_H_ */ diff --git a/common/include/Record.h b/common/include/Record.h index c1aca80..aafc4a0 100644 --- a/common/include/Record.h +++ b/common/include/Record.h @@ -21,6 +21,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class Record { private: @@ -37,5 +38,6 @@ namespace smartcard_service_api inline const ByteArray getData() const { return data; } }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* RECORD_H_ */ diff --git a/common/include/SEServiceHelper.h b/common/include/SEServiceHelper.h index 4afbfcb..cf65fa7 100644 --- a/common/include/SEServiceHelper.h +++ b/common/include/SEServiceHelper.h @@ -30,6 +30,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class SEServiceHelper : public Synchronous { protected: @@ -46,5 +47,6 @@ namespace smartcard_service_api virtual void shutdownSync() = 0; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SESERVICEHELPER_H_ */ diff --git a/common/include/SessionHelper.h b/common/include/SessionHelper.h index 3e220e6..85a15c1 100644 --- a/common/include/SessionHelper.h +++ b/common/include/SessionHelper.h @@ -31,6 +31,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ReaderHelper; typedef void (*openChannelCallback)(Channel *channel, int error, void *userData); @@ -106,5 +107,6 @@ namespace smartcard_service_api ErrorIllegalParameter &, ErrorSecurity &) = 0; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SESSIONHELPER_H_ */ diff --git a/common/include/TLVHelper.h b/common/include/TLVHelper.h index 04c6694..57c8c95 100644 --- a/common/include/TLVHelper.h +++ b/common/include/TLVHelper.h @@ -27,6 +27,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class TLVHelper { protected: @@ -82,5 +83,6 @@ namespace smartcard_service_api bool returnToParentTLV(); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* TLVHELPER_H_ */ diff --git a/common/include/Terminal.h b/common/include/Terminal.h index c26003a..af72b10 100644 --- a/common/include/Terminal.h +++ b/common/include/Terminal.h @@ -27,6 +27,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ typedef void (*terminalNotificationCallback)(const void *terminal, int event, int error, void *user_param); typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam); @@ -69,5 +70,6 @@ namespace smartcard_service_api virtual int getATR(terminalGetATRCallback callback, void *userData) = 0; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* TERMINAL_H_ */ diff --git a/gtest/CMakeLists.txt b/gtest/CMakeLists.txt new file mode 100644 index 0000000..acdc384 --- /dev/null +++ b/gtest/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gtest-smartcard-service C CXX) + +SET(GTEST_TEST "gtest-smartcard-service") +ADD_DEFINITIONS("-DUSE_DLOG") + +SET(REQUIRES_LIST ${REQUIRES_LIST} + glib-2.0 + gio-2.0 + gmock + dlog + capi-system-info +) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST}) + +FOREACH(flag ${GTEST_TEST_PKG_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +FILE(GLOB GTEST_TEST_SRCS *.cpp) +SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS}) + +ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS}) +TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov) + +INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin) diff --git a/gtest/common.h b/gtest/common.h new file mode 100755 index 0000000..1e8f621 --- /dev/null +++ b/gtest/common.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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. + */ +#ifndef __SMARTCARD_CONF_H__ +#define __SMARTCARD_CONF_H__ + +#include + +#ifdef USE_DLOG +#include +#undef LOG_TAG +#define LOG_TAG "SMARTCARD_SERVICE_GTEST" +#define GLOGD(format, args...) LOGD(format, ##args) +#else +#define GLOGD(format, args...) +#endif + +#define SE_FEATURE "http://tizen.org/feature/network.secure_element" +#define SE_UICC_FEATURE "http://tizen.org/feature/network.secure_element.uicc" +#define SE_ESE_FEATURE "http://tizen.org/feature/network.secure_element.ese" + + +typedef enum { + ERROR_NONE = 0, + ERROR_NOT_PERMITTED = -1, + ERROR_OUT_OF_MEMORY = -2, + ERROR_PERMISSION_DENIED = -3, + ERROR_RESOURCE_BUSY = -4, + ERROR_INVALID_OPERATION = -5, + ERROR_INVALID_PARAMETER = -6, + ERROR_NOT_SUPPORTED = -7, + ERROR_OPERATION_FAILED = -8, + ERROR_NOT_INITIALIZED = -9, + ERROR_ALREADY_INITIALIZED = -10, + ERROR_IN_PROGRESS = -11, +} error_e; +#endif /* __SMARTCARD_CONF_H__ */ diff --git a/gtest/gdbus.cpp b/gtest/gdbus.cpp new file mode 100644 index 0000000..32c9ea4 --- /dev/null +++ b/gtest/gdbus.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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 +#include +#include +#include +#include + +#include "gdbus.h" + +GDbus::GDbus() +{ + this->m_pConnection = NULL; + this->m_pCancellable = NULL; +} + +GDbus::~GDbus() +{ + GDBusConnection *conn = this->m_pConnection; + GCancellable *cancel = this->m_pCancellable; + + if (cancel) { + g_cancellable_cancel(cancel); + g_object_unref(cancel); + cancel = NULL; + } + + if (conn) { + g_object_unref(conn); + conn = NULL; + } +} + +error_e GDbus::Create(void) +{ + GError *err = NULL; + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + + this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (this->m_pConnection == NULL) { + if (err != NULL) { + GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message); + g_error_free(err); + } + + return ERROR_OPERATION_FAILED; + } + + this->m_pCancellable = g_cancellable_new(); + + return ERROR_NONE; +} + +error_e GDbus::Destroy(void) +{ + g_cancellable_cancel(this->m_pCancellable); + g_object_unref(this->m_pCancellable); + this->m_pCancellable = NULL; + + g_object_unref(this->m_pConnection); + this->m_pConnection = NULL; + + return ERROR_NONE; +} + +GDBusConnection *GDbus::GetConnection(void) +{ + return this->m_pConnection; +} + +GCancellable *GDbus::GetCancellable(void) +{ + return this->m_pCancellable; +} + +error_e GDbus::ConvertErrorStringToEnum(const char *error) +{ + if (NULL != strstr(error, "NoReply")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "Failed")) + return ERROR_OPERATION_FAILED; + else if (NULL != strstr(error, "UnknownMethod")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "InvalidArguments")) + return ERROR_INVALID_PARAMETER; + else if (NULL != strstr(error, "AccessDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "PermissionDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "NotSupported")) + return ERROR_NOT_SUPPORTED; + else if (NULL != strstr(error, "InProgress")) + return ERROR_IN_PROGRESS; + + return ERROR_OPERATION_FAILED; +} + +GVariant *GDbus::InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error) +{ + GError *error = NULL; + GVariant *reply = NULL; + GDBusConnection *connection = NULL; + *dbus_error = ERROR_NONE; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + *dbus_error = ERROR_NOT_INITIALIZED; + return reply; + } + + reply = g_dbus_connection_call_sync(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + GetCancellable(), + &error); + + if (reply == NULL) { + if (error != NULL) { + GLOGD("g_dbus_connection_call_sync() failed " + "error [%d: %s]", error->code, error->message); + *dbus_error = ConvertErrorStringToEnum(error->message); + g_error_free(error); + } else { + GLOGD("g_dbus_connection_call_sync() failed"); + *dbus_error = ERROR_OPERATION_FAILED; + } + + return NULL; + } + + return reply; +} diff --git a/gtest/gdbus.h b/gtest/gdbus.h new file mode 100644 index 0000000..f7ce6c2 --- /dev/null +++ b/gtest/gdbus.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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. + */ + +#ifndef __NET_CONFIG_GDBUS_H__ +#define __NET_CONFIG_GDBUS_H__ + +#include +#include + +#include "common.h" + +#define GMAINTIMEOUT 10000 +#define DBUS_REPLY_TIMEOUT (120 * 1000) + +#define SMARTCARD_SERVICE "org.tizen.SmartcardService" + +#define SMARTCARD_SE_SERVICE_PATH "/org/tizen/SmartcardService/SeService" +#define SMARTCARD_SE_SERVICE_INTERFACE "org.tizen.SmartcardService.SeService" + +#define SMARTCARD_READER_PATH "/org/tizen/SmartcardService/Reader" +#define SMARTCARD_READER_INTERFACE "org.tizen.SmartcardService.Reader" + +#define SMARTCARD_SESSION_PATH "/org/tizen/SmartcardService/Session" +#define SMARTCARD_SESSION_INTERFACE "org.tizen.SmartcardService.Session" + +#define SMARTCARD_CHANNEL_PATH "/org/tizen/SmartcardService/Channel" +#define SMARTCARD_CHANNEL_INTERFACE "org.tizen.SmartcardService.Channel" + +#define SMARTCARD_ACCESS_CONTROL_PATH "/org/tizen/SmartcardService/AccessControl" +#define SMARTCARD_ACCESS_CONTROL_INTERFACE "org.tizen.SmartcardService.AccessControl" + +#define SE_SERVICE "SeService" +#define SHUTDOWN "shutdown" +#define READER_INSERTED "ReaderInserted" +#define READER_REMOVED "ReaderRemoved" + +#define OPEN_SESSION "openSession" +#define GET_ATR "getATR" +#define OPEN_CHANNEL "openChannel" +#define CLOSE_SESSION "closeSession" + +#define TRANSMIT "transmit" +#define CLOSE_CHANNEL "closeChannel" + +#define IS_AUTHORIZED_EXTRA_ACCESS "isAuthorizedExtraAccess" +#define IS_AUTHORIZED_NFC_ACCESS "isAuthorizedNfcAccess" + +class GDbus { + private: + GDBusConnection *m_pConnection; + GCancellable *m_pCancellable; + public: + GDbus(); + ~GDbus(); + error_e Create(void); + error_e Destroy(void); + GDBusConnection *GetConnection(void); + GCancellable *GetCancellable(void); + error_e ConvertErrorStringToEnum(const char *error); + GVariant *InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); + error_e InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data); + GVariant *InvokeMethod_with_fd(GUnixFDList *fd_list, const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); +}; +#endif /* __NET_CONFIG_GDBUS_H__ */ diff --git a/gtest/smartcardService.cpp b/gtest/smartcardService.cpp new file mode 100644 index 0000000..c8fa7be --- /dev/null +++ b/gtest/smartcardService.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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 +#include +#include +#include +#include + +#include "smartcardService.h" + +smartcardService::smartcardService(void) +{ + Create(); +} + +smartcardService::~smartcardService(void) +{ + Destroy(); +} + +static void parseReaderInformation(GVariant *variant) +{ + GLOGD("+"); + GVariantIter *iter; + guint handle; + gchar *name; + + g_variant_get(variant, "a(us)", &iter); + + while (g_variant_iter_loop(iter, "(us)", &handle, &name) == true) + { + GLOGD("Reader : name [%s], handle [%08x]", name, handle); + + } + + g_variant_iter_free(iter); + +} + +error_e smartcardService::SeService(guint *handle) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariant *readers = NULL; + gint result; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_SE_SERVICE_PATH, + SMARTCARD_SE_SERVICE_INTERFACE, + SE_SERVICE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(iu@a(us))", &result, handle, &readers); + parseReaderInformation(readers); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::shutdown(guint handle) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + gint result; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_SE_SERVICE_PATH, + SMARTCARD_SE_SERVICE_INTERFACE, + SHUTDOWN, + g_variant_new("(u)", handle), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::openSession(guint service_id, guint reader_id, guint *reader_handle) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + gint result; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_READER_PATH, + SMARTCARD_READER_INTERFACE, + OPEN_SESSION, + g_variant_new("(uu)", service_id, reader_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(iu)", &result, &reader_handle); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::getATR(guint service_id, guint session_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_SESSION_PATH, + SMARTCARD_SESSION_INTERFACE, + GET_ATR, + g_variant_new("(uu)", service_id, session_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::openChannel(guint service_id, guint session_id, guint type) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + GVariant *atr; + GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + g_variant_builder_add(builder, "(y)", 0x00); + g_variant_builder_add(builder, "(y)", 0x00); + atr = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + unsigned char p2 = 0x00; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_SESSION_PATH, + SMARTCARD_SESSION_INTERFACE, + OPEN_CHANNEL, + g_variant_new("(uuu@a(y)y)", service_id, session_id, type, atr, p2), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::closeSession(guint service_id, guint session_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_SESSION_PATH, + SMARTCARD_SESSION_INTERFACE, + CLOSE_SESSION, + g_variant_new("(uu)", service_id, session_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::closeChannel(guint service_id, guint channel_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_CHANNEL_PATH, + SMARTCARD_CHANNEL_INTERFACE, + CLOSE_CHANNEL, + g_variant_new("(uu)", service_id, channel_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e smartcardService::transmit(guint service_id, guint channel_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + GVariant *command; + GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + g_variant_builder_add(builder, "(y)", 0x00); + g_variant_builder_add(builder, "(y)", 0x00); + command = g_variant_new("a(y)", builder); + g_variant_builder_unref(builder); + + message = InvokeMethod(SMARTCARD_SERVICE, + SMARTCARD_CHANNEL_PATH, + SMARTCARD_CHANNEL_INTERFACE, + TRANSMIT, + g_variant_new("(uu@a(y))", service_id, channel_id, command), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/gtest/smartcardService.h b/gtest/smartcardService.h new file mode 100644 index 0000000..2f11491 --- /dev/null +++ b/gtest/smartcardService.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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. + */ +#ifndef __SMARTCARD_SERVICE_H__ +#define __SMARTCARD_SERVICE_H__ + +#include +#include + +#include "gdbus.h" + +class smartcardService:public GDbus { + private: + public: + smartcardService(void); + ~smartcardService(void); + error_e shutdown(guint handle); + error_e SeService(guint *handle); + error_e openSession(guint service_id, guint reader_id, guint *reader_handle); + error_e getATR(guint service_id, guint session_id); + error_e openChannel(guint service_id, guint session_id, guint type); + error_e transmit(guint service_id, guint channel_id); + error_e closeChannel(guint service_id, guint channel_id); + error_e closeSession(guint service_id, guint session_id); +}; + +#endif /* __SMARTCARD_SERVICE_H__ */ diff --git a/gtest/unittest.cpp b/gtest/unittest.cpp new file mode 100644 index 0000000..1d94306 --- /dev/null +++ b/gtest/unittest.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "smartcardService.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +static guint handle = 0; +static guint reader_handle = 0; + +bool _is_support_smartcard() +{ + bool ret = false; + bool is_supported_se = false; + bool is_supported_se_uicc = false; + bool is_supported_se_ese = false; + + system_info_get_platform_bool(SE_FEATURE, &is_supported_se); + system_info_get_platform_bool(SE_UICC_FEATURE, &is_supported_se_uicc); + system_info_get_platform_bool(SE_ESE_FEATURE, &is_supported_se_ese); + + if(is_supported_se && (is_supported_se_uicc || is_supported_se_ese)) + ret = true; + + return ret; +} + +TEST(smartcardServiceSeService_t, SeService_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.SeService(&handle); + EXPECT_EQ(ERROR_NONE, ret); +} + + +TEST(smartcardServiceReader_t, openSession_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.openSession(handle, 0, &reader_handle); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(smartcardServiceReader_t, getATR_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.getATR(handle, reader_handle); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(smartcardServiceReader_t, openChannel_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.openChannel(handle, reader_handle, 0); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(smartcardServiceChannel, transmit_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.transmit(handle, 0); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(smartcardServiceChannel, closeChannel_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.closeChannel(handle, 0); + EXPECT_EQ(ERROR_NONE, ret); +} + + +TEST(smartcardServiceReader_t, closeSession_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.closeSession(handle, reader_handle); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(smartcardServiceSeService_t, shutdown_p) +{ + ASSERT_EQ(_is_support_smartcard(), true); + + int ret = 0; + smartcardService S; + + ret = S.shutdown(handle); + EXPECT_EQ(ERROR_NONE, ret); +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/packaging/smartcard-service.spec b/packaging/smartcard-service.spec index d431a90..b6574dd 100755 --- a/packaging/smartcard-service.spec +++ b/packaging/smartcard-service.spec @@ -29,6 +29,7 @@ BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-creds-gdbus) BuildRequires: pkgconfig(cynara-session) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: python BuildRequires: python-xml @@ -39,6 +40,9 @@ Requires(postun): /sbin/ldconfig Requires: %{name}-common = %{version}-%{release} Requires: security-config +%if 0%{?gtests:1} +BuildRequires: pkgconfig(gmock) +%endif %description Smartcard Service FW. @@ -61,7 +65,9 @@ Smartcard Service FW. %{bindir}/author-signature.xml %{bindir}/signature1.xml /etc/dbus-1/system.d/org.tizen.SmartcardService.conf - +%if 0%{?gtests:1} +%{_bindir}/gtest* +%endif %post /usr/bin/signing-client/hash-signer-client.sh -a -d -p platform %{bindir} @@ -131,15 +137,25 @@ common smartcard service. %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov " +%endif + %if 0%{?sec_build_binary_debug_enable} export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif export LDFLAGS+="-Wl,-Bsymbolic-functions" + + mkdir obj-arm-limux-qnueabi cd obj-arm-limux-qnueabi -%cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} %{?use_autostart} %{?use_gdbus} %{?test_client} +%cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} %{?use_autostart} %{?use_gdbus} %{?test_client} \ + -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \ + -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} %install cd obj-arm-limux-qnueabi diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 28baa1e..220f833 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -10,6 +10,10 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ SRCS) ### for private ADD_DEFINITIONS("-D__PRIVATE") +IF(BUILD_GTESTS) + ADD_DEFINITIONS(-DBUILD_GTEST) +ENDIF(BUILD_GTESTS) + FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS " \\ diff --git a/server/ClientInstance.cpp b/server/ClientInstance.cpp index 8f91315..2606405 100644 --- a/server/ClientInstance.cpp +++ b/server/ClientInstance.cpp @@ -35,7 +35,7 @@ namespace smartcard_service_api if (result != NULL) { mapServices.insert(make_pair(result->getHandle(), result)); } else { - _ERR("alloc failed"); + _ERR("alloc failed"); //LCOV_EXCL_LINE } return result; @@ -43,6 +43,7 @@ namespace smartcard_service_api ServiceInstance *ClientInstance::getService(unsigned int handle) { + /* LCOV_EXCL_START */ ServiceInstance *result = NULL; map::iterator item; @@ -52,10 +53,12 @@ namespace smartcard_service_api } return result; + /* LCOV_EXCL_STOP */ } void ClientInstance::removeService(unsigned int handle) { + /* LCOV_EXCL_START */ map::iterator item; if ((item = mapServices.find(handle)) != mapServices.end()) @@ -63,6 +66,7 @@ namespace smartcard_service_api delete item->second; mapServices.erase(item); } + /* LCOV_EXCL_STOP */ } void ClientInstance::removeServices() diff --git a/server/ServerChannel.cpp b/server/ServerChannel.cpp index 295adac..b89b94c 100644 --- a/server/ServerChannel.cpp +++ b/server/ServerChannel.cpp @@ -25,6 +25,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ ServerChannel::ServerChannel(ServerSession *session, void *caller, int channelNum, Terminal *terminal) : Channel(session), terminal(terminal), caller(caller), @@ -108,4 +109,5 @@ namespace smartcard_service_api return ret; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/ServerGDBus.cpp b/server/ServerGDBus.cpp index f40ac58..26698d6 100755 --- a/server/ServerGDBus.cpp +++ b/server/ServerGDBus.cpp @@ -104,10 +104,12 @@ namespace smartcard_service_api dispatcher->syncLock(); dispatcher->q.pop(); + /* LCOV_EXCL_START */ if (dispatcher->q.size() > 0) { _INFO("remaining messages : %d", dispatcher->q.size()); result = true; + /* LCOV_EXCL_STOP */ } else { _INFO("dispatch finished"); } @@ -140,11 +142,12 @@ namespace smartcard_service_api const gchar *name, const gchar *old_owner, const gchar *new_owner, void *user_data) { + /* LCOV_EXCL_START */ if (name == NULL || old_owner == NULL || new_owner == NULL) { _ERR("invalid parameter"); return; } - + /* LCOV_EXCL_STOP */ if (strlen(new_owner) == 0) { ClientInstance *client; @@ -198,10 +201,12 @@ namespace smartcard_service_api &error); if (dbus_proxy == NULL) { + /* LCOV_EXCL_START */ _ERR("Can not create proxy : %s", error->message); g_error_free(error); return false; + /* LCOV_EXCL_STOP */ } /* subscribe signal */ @@ -232,12 +237,14 @@ namespace smartcard_service_api connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection != NULL) { + /* LCOV_EXCL_START */ } else { _ERR("Can not get connection %s", error->message); g_error_free(error); return false; } + /* LCOV_EXCL_STOP */ _init(); @@ -295,10 +302,12 @@ namespace smartcard_service_api if (_call_get_connection_unix_process_id_sync( (GDBusProxy *)dbus_proxy, name, &pid, NULL, &error) == true) { + /* LCOV_EXCL_START */ } else { _ERR("_g_freedesktop_dbus_call_get_connection_unix_process_id_sync failed : %s", error->message); g_error_free(error); } + /* LCOV_EXCL_STOP */ return pid; } @@ -321,34 +330,42 @@ namespace smartcard_service_api pid = ServerGDBus::getInstance().getPID(sender_unique_name); ret = cynara_initialize(&p_cynara, NULL); + /* LCOV_EXCL_START */ if (ret != CYNARA_API_SUCCESS) { _ERR("cynara_initialize() failed"); return false; } + /* LCOV_EXCL_STOP */ ret = cynara_creds_gdbus_get_user(connection, sender_unique_name, USER_METHOD_DEFAULT, &user); + /* LCOV_EXCL_START */ if (ret != CYNARA_API_SUCCESS) { _ERR("cynara_creds_gdbus_get_user() failed"); return false; } + /* LCOV_EXCL_STOP */ ret = cynara_creds_gdbus_get_client(connection, sender_unique_name, CLIENT_METHOD_DEFAULT, &client); + /* LCOV_EXCL_START */ if (ret != CYNARA_API_SUCCESS) { _ERR("cynara_creds_gdbus_get_client() failed"); g_free(user); return false; } + /* LCOV_EXCL_STOP */ _ERR("user :%s , client :%s ,unique_name : %s, pid() : %d", user, client, sender_unique_name, pid); client_session = cynara_session_from_pid(pid); + /* LCOV_EXCL_START */ if (!client_session) { _ERR("cynara_session_from_pid() failed"); g_free(client); g_free(user); return false; } + /* LCOV_EXCL_STOP */ ret = cynara_check(p_cynara, client, client_session, user, SMARTCARD_PRIVILEGE); if ( ret == CYNARA_API_ACCESS_ALLOWED ) { @@ -439,7 +456,7 @@ namespace smartcard_service_api /* generate certification hashes */ instance->generateCertificationHashes(); } else { - _ERR("createClient failed"); + _ERR("createClient failed"); /* LCOV_EXCL_LINE */ } } @@ -455,6 +472,7 @@ namespace smartcard_service_api if (list.size() == 0) { _INFO("no secure elements"); } + /* LCOV_EXCL_START */ } else { _ERR("createService failed"); @@ -470,6 +488,7 @@ namespace smartcard_service_api result = SCARD_ERROR_IPC_FAILED; } + /* LCOV_EXCL_STOP */ readers = _reader_to_variant(list); @@ -486,11 +505,13 @@ namespace smartcard_service_api GDBusMethodInvocation *invocation; void *user_data; + /* LCOV_EXCL_START */ if (params.size() != 3) { _ERR("invalid parameter"); return; } + /* LCOV_EXCL_STOP */ object = (SmartcardServiceSeService *)params[0]; invocation = (GDBusMethodInvocation *)params[1]; @@ -519,6 +540,7 @@ namespace smartcard_service_api params.push_back((void *)user_data); GDBusDispatcher::push(_process_se_service, params); + /* LCOV_EXCL_START */ } else { vector > list; @@ -531,6 +553,7 @@ namespace smartcard_service_api IntegerHandle::INVALID_HANDLE, _reader_to_variant(list)); } + /* LCOV_EXCL_STOP */ return true; } @@ -566,11 +589,13 @@ namespace smartcard_service_api guint handle; void *user_data; + /* LCOV_EXCL_START */ if (params.size() != 4) { _ERR("invalid parameter"); return; } + /* LCOV_EXCL_STOP */ object = (SmartcardServiceSeService *)params[0]; invocation = (GDBusMethodInvocation *)params[1]; @@ -602,6 +627,7 @@ namespace smartcard_service_api params.push_back(user_data); GDBusDispatcher::push(_process_shutdown, params); + /* LCOV_EXCL_START */ } else { _ERR("access denied"); @@ -609,6 +635,7 @@ namespace smartcard_service_api smartcard_service_se_service_complete_shutdown(object, invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED); } + /* LCOV_EXCL_STOP */ return true; } @@ -629,6 +656,7 @@ namespace smartcard_service_api G_CALLBACK(_handle_shutdown), this); + /* LCOV_EXCL_START */ if (g_dbus_interface_skeleton_export( G_DBUS_INTERFACE_SKELETON(seService), connection, @@ -643,6 +671,7 @@ namespace smartcard_service_api return false; } + /* LCOV_EXCL_STOP */ return true; } @@ -658,17 +687,21 @@ namespace smartcard_service_api void ServerGDBus::emitReaderInserted(unsigned int reader_id, const char *reader_name) { + /* LCOV_EXCL_START */ smartcard_service_se_service_emit_reader_inserted( SMARTCARD_SERVICE_SE_SERVICE(seService), reader_id, reader_name); + /* LCOV_EXCL_STOP */ } void ServerGDBus::emitReaderRemoved(unsigned int reader_id, const char *reader_name) { + /* LCOV_EXCL_START */ smartcard_service_se_service_emit_reader_removed( SMARTCARD_SERVICE_SE_SERVICE(seService), reader_id, reader_name); + /* LCOV_EXCL_STOP */ } /* Reader * @@ -700,6 +733,7 @@ namespace smartcard_service_api if (handle != IntegerHandle::INVALID_HANDLE) { result = SCARD_ERROR_OK; } else { + /* LCOV_EXCL_START */ _ERR("createSession failed [%d]", handle); result = SCARD_ERROR_OUT_OF_MEMORY; @@ -708,6 +742,7 @@ namespace smartcard_service_api _ERR("request invalid reader handle [%d]", reader_id); result = SCARD_ERROR_ILLEGAL_PARAM; + /* LCOV_EXCL_STOP */ } /* response to client */ @@ -726,9 +761,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 5) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceReader *)params[0]; @@ -765,6 +802,7 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_open_session, params); } else { + /* LCOV_EXCL_START */ _ERR("access denied"); /* response to client */ @@ -772,6 +810,7 @@ namespace smartcard_service_api invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED, IntegerHandle::INVALID_HANDLE); + /* LCOV_EXCL_STOP */ } return true; @@ -794,6 +833,7 @@ namespace smartcard_service_api "/org/tizen/SmartcardService/Reader", &error) == false) { + /* LCOV_EXCL_START */ _ERR("Can not skeleton_export %s", error->message); g_error_free(error); @@ -801,6 +841,7 @@ namespace smartcard_service_api reader = NULL; return false; + /* LCOV_EXCL_STOP */ } return true; @@ -808,10 +849,12 @@ namespace smartcard_service_api void ServerGDBus::deinitReader() { + /* LCOV_EXCL_START */ if (reader != NULL) { g_object_unref(reader); reader = NULL; } + /* LCOV_EXCL_STOP */ } /* Session * @@ -835,7 +878,7 @@ namespace smartcard_service_api resource.removeSession(name, service_id, session_id); } else { - _ERR("invalid parameters"); + _ERR("invalid parameters"); //LCOV_EXCL_LINE } /* response to client */ @@ -854,9 +897,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 5) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceSession *)params[0]; @@ -893,11 +938,13 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_close_session, params); } else { + /* LCOV_EXCL_START */ _ERR("access denied"); /* response to client */ smartcard_service_session_complete_close_session(object, invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED); + /* LCOV_EXCL_STOP */ } return true; @@ -920,6 +967,7 @@ namespace smartcard_service_api name = g_dbus_method_invocation_get_sender(invocation); client = resource.getService(name, service_id); + /* LCOV_EXCL_START */ if (client != NULL) { Terminal *terminal; @@ -947,6 +995,7 @@ namespace smartcard_service_api result = SCARD_ERROR_UNAVAILABLE; } + /* LCOV_EXCL_STOP */ atr = GDBusHelper::convertByteArrayToVariant(resp); @@ -966,9 +1015,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 5) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceSession *)params[0]; @@ -1005,6 +1056,7 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_get_atr, params); } else { + /* LCOV_EXCL_START */ ByteArray resp; _ERR("access denied"); @@ -1015,6 +1067,7 @@ namespace smartcard_service_api invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED, GDBusHelper::convertByteArrayToVariant(resp)); + /* LCOV_EXCL_STOP */ } return true; @@ -1047,6 +1100,7 @@ namespace smartcard_service_api channelID = resource.createChannel(name, service_id, session_id, type, tempAid); + /* LCOV_EXCL_START */ if (channelID != IntegerHandle::INVALID_HANDLE) { ServerChannel *temp; @@ -1066,6 +1120,7 @@ namespace smartcard_service_api /* set error value */ result = SCARD_ERROR_UNAVAILABLE; } + /* LCOV_EXCL_STOP */ } catch (ExceptionBase &e) { @@ -1093,9 +1148,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 8) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceSession *)params[0]; @@ -1141,6 +1198,7 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_open_channel, params); } else { + /* LCOV_EXCL_START */ ByteArray resp; _ERR("access denied"); @@ -1152,6 +1210,7 @@ namespace smartcard_service_api IntegerHandle::INVALID_HANDLE, -1, GDBusHelper::convertByteArrayToVariant(resp)); + /* LCOV_EXCL_STOP */ } return true; @@ -1184,6 +1243,7 @@ namespace smartcard_service_api "/org/tizen/SmartcardService/Session", &error) == false) { + /* LCOV_EXCL_START */ _ERR("Can not skeleton_export %s", error->message); g_error_free(error); @@ -1191,6 +1251,7 @@ namespace smartcard_service_api session = NULL; return false; + /* LCOV_EXCL_STOP */ } return true; @@ -1241,9 +1302,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 5) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceChannel *)params[0]; @@ -1279,6 +1342,7 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_close_channel, params); } else { + /* LCOV_EXCL_START */ _ERR("access denied"); /* response to client */ @@ -1286,6 +1350,7 @@ namespace smartcard_service_api object, invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED); + /* LCOV_EXCL_STOP */ } return true; @@ -1311,6 +1376,7 @@ namespace smartcard_service_api name = g_dbus_method_invocation_get_sender(invocation); channel = resource.getChannel(name, service_id, channel_id); + /* LCOV_EXCL_START */ if (channel != NULL) { int rv; ByteArray cmd; @@ -1330,6 +1396,7 @@ namespace smartcard_service_api result = SCARD_ERROR_UNAVAILABLE; } + /* LCOV_EXCL_STOP */ response = GDBusHelper::convertByteArrayToVariant(resp); @@ -1350,9 +1417,11 @@ namespace smartcard_service_api void *user_data; if (params.size() != 6) { + /* LCOV_EXCL_START */ _ERR("invalid parameter"); return; + /* LCOV_EXCL_STOP */ } object = (SmartcardServiceChannel *)params[0]; @@ -1398,6 +1467,7 @@ namespace smartcard_service_api GDBusDispatcher::push(_process_transmit, params); } else { + /* LCOV_EXCL_START */ ByteArray resp; _ERR("access denied"); @@ -1407,6 +1477,7 @@ namespace smartcard_service_api invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED, GDBusHelper::convertByteArrayToVariant(resp)); + /* LCOV_EXCL_STOP */ } return true; @@ -1434,6 +1505,7 @@ namespace smartcard_service_api "/org/tizen/SmartcardService/Channel", &error) == false) { + /* LCOV_EXCL_START */ _ERR("Can not skeleton_export %s", error->message); g_error_free(error); @@ -1441,6 +1513,7 @@ namespace smartcard_service_api channel = NULL; return false; + /* LCOV_EXCL_STOP */ } return true; diff --git a/server/ServerReader.cpp b/server/ServerReader.cpp index 580c697..877f7c2 100644 --- a/server/ServerReader.cpp +++ b/server/ServerReader.cpp @@ -30,6 +30,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ ServerReader::ServerReader(ServerSEService *seService, const char *name, Terminal *terminal) : ReaderHelper() { @@ -87,4 +88,5 @@ namespace smartcard_service_api return session; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/ServerResource.cpp b/server/ServerResource.cpp index 5e9f68b..48aa04d 100644 --- a/server/ServerResource.cpp +++ b/server/ServerResource.cpp @@ -109,10 +109,10 @@ namespace smartcard_service_api mapClients.insert(make_pair(name, instance)); result = true; } else { - _ERR("alloc failed"); + _ERR("alloc failed"); //LCOV_EXCL_LINE } } else { - _ERR("client already exist, name [%s]", name); + _ERR("client already exist, name [%s]", name); //LCOV_EXCL_LINE } return result; @@ -139,10 +139,11 @@ namespace smartcard_service_api delete item->second; mapClients.erase(item); } else { - _DBG("client removed already, name [%s]", name); + _DBG("client removed already, name [%s]", name); //LCOV_EXCL_LINE } } + /* LCOV_EXCL_START */ void ServerResource::removeClients() { map::iterator item; @@ -762,7 +763,7 @@ namespace smartcard_service_api snprintf(fullPath, sizeof(fullPath), "%s/%s", OMAPI_SE_PATH, entry->d_name); - SECURE_LOGD("se name [%s]", fullPath); + SECURE_LOGD("se name [%s]", fullPath); //LCOV_EXCL_LINE result = appendSELibrary(fullPath); } @@ -1104,6 +1105,7 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ void ServerResource::finish() { diff --git a/server/ServerSEService.cpp b/server/ServerSEService.cpp index d4f094e..3a62462 100644 --- a/server/ServerSEService.cpp +++ b/server/ServerSEService.cpp @@ -32,6 +32,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ #define OMAPI_SE_PATH "/usr/lib/se" ServerSEService::ServerSEService():SEServiceHelper() @@ -221,4 +222,5 @@ namespace smartcard_service_api } } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/ServerSession.cpp b/server/ServerSession.cpp index 3bf6829..c0c6ac9 100755 --- a/server/ServerSession.cpp +++ b/server/ServerSession.cpp @@ -30,6 +30,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ ServerSession::ServerSession(ServerReader *reader, const vector &certHashes, void *caller, Terminal *terminal) : SessionHelper(reader) @@ -299,4 +300,5 @@ namespace smartcard_service_api return openLogicalChannelSync(temp, caller); } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/ServiceInstance.cpp b/server/ServiceInstance.cpp index 9cc0429..2d69869 100755 --- a/server/ServiceInstance.cpp +++ b/server/ServiceInstance.cpp @@ -42,6 +42,7 @@ namespace smartcard_service_api } } + /* LCOV_EXCL_START */ unsigned int ServiceInstance::openSession(Terminal *terminal, const vector &certHashes, void *caller) { unsigned int handle = IntegerHandle::assignHandle(); @@ -213,4 +214,5 @@ namespace smartcard_service_api mapChannels.clear(); } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/include/ClientInstance.h b/server/include/ClientInstance.h index 25a0bfc..7cef69d 100644 --- a/server/include/ClientInstance.h +++ b/server/include/ClientInstance.h @@ -29,6 +29,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ClientInstance { private : @@ -57,6 +58,7 @@ namespace smartcard_service_api inline vector &getCertificationHashes() { return certHashes; } }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* CLIENTINSTANCE_H_ */ diff --git a/server/include/ServerChannel.h b/server/include/ServerChannel.h index 1df1576..cb27435 100644 --- a/server/include/ServerChannel.h +++ b/server/include/ServerChannel.h @@ -28,6 +28,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ServerChannel: public Channel { private: @@ -60,5 +61,6 @@ namespace smartcard_service_api friend class ServerResource; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SERVERCHANNEL_H_ */ diff --git a/server/include/ServerReader.h b/server/include/ServerReader.h index 063410b..f29b21a 100644 --- a/server/include/ServerReader.h +++ b/server/include/ServerReader.h @@ -33,6 +33,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ServerSEService; class ServerReader : public ReaderHelper @@ -58,5 +59,6 @@ namespace smartcard_service_api friend class ServerSEService; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SERVERREADER_H_ */ diff --git a/server/include/ServerSEService.h b/server/include/ServerSEService.h index b5c8d5e..efeb65f 100644 --- a/server/include/ServerSEService.h +++ b/server/include/ServerSEService.h @@ -31,6 +31,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ServerSEService : public SEServiceHelper { private: @@ -64,5 +65,6 @@ namespace smartcard_service_api friend class ServerDispatcher; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SERVERSESERVICE_H_ */ diff --git a/server/include/ServerSession.h b/server/include/ServerSession.h index 4f9ec46..0d296f7 100644 --- a/server/include/ServerSession.h +++ b/server/include/ServerSession.h @@ -33,6 +33,7 @@ using namespace std; namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ServerReader; class ServerSession : public SessionHelper @@ -94,5 +95,6 @@ namespace smartcard_service_api friend class ServiceInstance; }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SERVERSESSION_H_ */ diff --git a/server/include/ServiceInstance.h b/server/include/ServiceInstance.h index a1acaea..d25f1b0 100644 --- a/server/include/ServiceInstance.h +++ b/server/include/ServiceInstance.h @@ -29,6 +29,7 @@ namespace smartcard_service_api { + /* LCOV_EXCL_START */ class ClientInstance; class ServiceInstance @@ -66,5 +67,6 @@ namespace smartcard_service_api void closeChannels(); }; + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ #endif /* SERVICEINSTANCE_H_ */ diff --git a/server/private/AccessControl.cpp b/server/private/AccessControl.cpp index 502ce9d..ee629cf 100644 --- a/server/private/AccessControl.cpp +++ b/server/private/AccessControl.cpp @@ -43,6 +43,7 @@ static void _load_granted_package_info() mapGranted.insert(make_pair("nfc-manager", ByteArray::EMPTY)); } +/* LCOV_EXCL_START */ static gboolean _compare_hash(char *package, ByteArray &hash) { gboolean result = false; @@ -67,6 +68,10 @@ static gboolean _compare_hash(char *package, ByteArray &hash) static gboolean _check_permission(pid_t pid) { +#if (BUILD_GTEST != 0) + return true; +#endif + gboolean result = false; char package[1024]; @@ -92,6 +97,7 @@ static gboolean _check_permission(pid_t pid) static bool _get_se_name(unsigned int se_type, char *buf, size_t len) { + bool result = false; switch ((se_type >> 4) & 0x0F) { @@ -528,6 +534,7 @@ static gboolean _handle_is_authorized_extra_access( return true; } +/* LCOV_EXCL_STOP */ static bool _init_access_control(void *connection) { @@ -551,6 +558,7 @@ static bool _init_access_control(void *connection) "/org/tizen/SmartcardService/AccessControl", &error) == false) { + /* LCOV_EXCL_START */ _ERR("Can not skeleton_export %s", error->message); g_error_free(error); @@ -558,6 +566,7 @@ static bool _init_access_control(void *connection) access_control = NULL; return false; + /* LCOV_EXCL_STOP */ } return true; diff --git a/server/private/PKCS15CDFACL.cpp b/server/private/PKCS15CDFACL.cpp index e0c8d0a..31ce64c 100644 --- a/server/private/PKCS15CDFACL.cpp +++ b/server/private/PKCS15CDFACL.cpp @@ -39,6 +39,7 @@ namespace smartcard_service_api { } + /* LCOV_EXCL_START */ int PKCS15CDFACL::loadACL(Channel *channel) { int result = SCARD_ERROR_OK; @@ -118,4 +119,5 @@ namespace smartcard_service_api return result; } + /* LCOV_EXCL_STOP */ } /* namespace smartcard_service_api */ diff --git a/server/smartcard-daemon.cpp b/server/smartcard-daemon.cpp index b58384d..ed2adad 100755 --- a/server/smartcard-daemon.cpp +++ b/server/smartcard-daemon.cpp @@ -42,6 +42,10 @@ using namespace smartcard_service_api; /* global variable */ GMainLoop *main_loop = NULL; +#if (BUILD_GCOV != 0) +extern "C" void __gcov_flush(void); +#endif + #ifndef USE_AUTOSTART static void daemonize(void) { @@ -101,6 +105,7 @@ static void _name_acquired_cb(GDBusConnection *connection, _DBG("name : %s", name); } +/* LCOV_EXCL_START */ static void _name_lost_cb(GDBusConnection *connnection, const gchar *name, gpointer user_data) { @@ -112,7 +117,11 @@ static void _name_lost_cb(GDBusConnection *connnection, static void __sighandler(int sig) { _DBG("signal!! [%d]", sig); +#if (BUILD_GCOV != 0) + __gcov_flush(); +#endif } +/* LCOV_EXCL_STOP */ int main(int argc, char *argv[]) { @@ -123,6 +132,10 @@ int main(int argc, char *argv[]) daemonize(); #endif +#if (BUILD_GCOV != 0) + setenv("GCOV_PREFIX", "/tmp/", 1); +#endif + main_loop = g_main_loop_new(NULL, FALSE); id = g_bus_own_name(G_BUS_TYPE_SYSTEM, @@ -142,6 +155,10 @@ int main(int argc, char *argv[]) /* release secure element.. (pure virtual function problem..) */ ServerResource::getInstance().unloadSecureElements(); +#if (BUILD_GCOV != 0) + __gcov_flush(); +#endif + return 0; }