Skip to content

Commit

Permalink
build: add ios xctest support
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Dec 24, 2023
1 parent 7756385 commit fd262a7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4095,7 +4095,7 @@ if (GUI)
RESOURCE "${ALLRESOURCES}"
MACOSX_BUNDLE_ICON_FILE yass.icns
MACOSX_BUNDLE_COPYRIGHT "${YASS_APP_COPYRIGHT}"
MACOSX_BUNDLE_GUI_IDENTIFIER "it.gui.yass"
MACOSX_BUNDLE_GUI_IDENTIFIER "it.gui.ios.yass"
MACOSX_BUNDLE_BUNDLE_NAME ${PACKAGE_NAME}
MACOSX_BUNDLE_INFO_PLIST ${APP_MACOSX_BUNDLE_INFO}
XCODE_GENERATE_SCHEME "TRUE"
Expand Down Expand Up @@ -4189,7 +4189,7 @@ endif()
# *****************************************************************************************

if (BUILD_TESTS)
add_executable(yass_test
set(yass_test_SOURCE
src/test_util.cpp
src/network_test.cpp
src/ss_test.cpp
Expand All @@ -4200,6 +4200,26 @@ if (BUILD_TESTS)
src/core/process_utils_test.cpp
src/core/utils_test.cpp
)

if (IOS)
enable_testing()
find_package(XCTest REQUIRED)

xctest_add_bundle(yass_test ${APP_NAME}
src/ss_test.mm
${yass_test_SOURCE})

xctest_add_test(XCTest.${APP_NAME} yass_test)

if (XCODE_CODESIGN_IDENTITY OR XCODE_DEPLOYMENT_TEAM)
set_target_properties(yass_test PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${XCODE_CODESIGN_IDENTITY}"
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${XCODE_DEPLOYMENT_TEAM}"
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Auto")
endif()
else()
add_executable(yass_test ${yass_test_SOURCE})
endif()
if (USE_LEVELDB)
target_sources(yass_test PRIVATE third_party/leveldb_test.cc)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/core/c-ares_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "test_util.hpp"
#include "core/c-ares.hpp"

#ifdef OS_ANDROID
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
ABSL_FLAG(bool, no_cares_tests, true, "skip c-ares tests");
#else
ABSL_FLAG(bool, no_cares_tests, false, "skip c-ares tests");
Expand Down
2 changes: 1 addition & 1 deletion src/core/process_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "core/logging.hpp"
#include "core/utils.hpp"

#ifdef OS_ANDROID
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
ABSL_FLAG(bool, no_exec_proc_tests, true, "skip execute_process tests");
#else
ABSL_FLAG(bool, no_exec_proc_tests, false, "skip execute_process tests");
Expand Down
2 changes: 1 addition & 1 deletion src/ios/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleIconFile</key>
<string>yass</string>
<key>CFBundleIdentifier</key>
<string>it.gui.yass</string>
<string>it.gui.ios.yass</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
Expand Down
7 changes: 7 additions & 0 deletions src/ss_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,14 @@ INSTANTIATE_TEST_SUITE_P(Ss, EndToEndTest, ::testing::ValuesIn(kCiphers),
return to_cipher_method_name(info.param);
});

#if BUILDFLAG(IS_IOS)
extern "C" int xc_main();
int xc_main() {
int argc = 1;
char *argv[] = {(char*)"xc_main", nullptr};
#else
int main(int argc, char **argv) {
#endif
SetExecutablePath(argv[0]);
std::string exec_path;
if (!GetExecutablePath(&exec_path)) {
Expand Down
20 changes: 20 additions & 0 deletions src/ss_test.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Chilledheart */

#import <XCTest/XCTest.h>

extern "C" int xc_main();

@interface YassTests : XCTestCase

@end

@implementation YassTests

- (void)testGtest {
XCTAssertEqual(0, xc_main());
}

@end


22 changes: 18 additions & 4 deletions tools/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var macosxCodeSignIdentityFlag string
var iosVersionMinFlag string
var iosCodeSignIdentityFlag string
var iosDevelopmentTeamFlag string
var iosTestDeviceNameFlag string

var msvcTargetArchFlag string
var msvcCrtLinkageFlag string
Expand Down Expand Up @@ -167,6 +168,7 @@ func InitFlag() {
flag.StringVar(&iosVersionMinFlag, "ios-version-min", getEnv("MACOSX_DEPLOYMENT_TARGET", "13.0"), "Set iOS deployment target, such as 13.0")
flag.StringVar(&iosCodeSignIdentityFlag, "ios-codesign-identity", getEnv("CODESIGN_IDENTITY", "-"), "Set iOS CodeSign Identity")
flag.StringVar(&iosDevelopmentTeamFlag, "ios-development-team", getEnv("DEVELOPMENT_TEAM", ""), "Set iOS deployment team")
flag.StringVar(&iosTestDeviceNameFlag, "ios-test-device-name", getEnv("IPHONE_NAME", ""), "Set iOS test device name")

flag.StringVar(&msvcTargetArchFlag, "msvc-tgt-arch", getEnv("VSCMD_ARG_TGT_ARCH", "x64"), "Set Visual C++ Target Achitecture")
flag.StringVar(&msvcCrtLinkageFlag, "msvc-crt-linkage", getEnv("MSVC_CRT_LINKAGE", "static"), "Set Visual C++ CRT Linkage")
Expand Down Expand Up @@ -1060,11 +1062,23 @@ func buildStageExecuteBuildScript() {
}
}
if runTestFlag {
checkCmd := []string{"./yass_test"}
if verboseFlag > 0 {
checkCmd = []string{"./yass_test", "-v", fmt.Sprintf("%d", verboseFlag), "-logtostderr"}
if systemNameFlag == "ios" && subSystemNameFlag == "simulator" {
xcodeCmd := []string{"xcodebuild", "test", "-configuration", cmakeBuildTypeFlag,
"-jobs", fmt.Sprintf("%d", cmakeBuildConcurrencyFlag),
"-scheme", "yass", "-destination", "platform=iOS Simulator,name=iPhone 15 Pro"}
cmdRun(xcodeCmd, true)
} else if systemNameFlag == "ios" {
xcodeCmd := []string{"xcodebuild", "test", "-configuration", cmakeBuildTypeFlag,
"-jobs", fmt.Sprintf("%d", cmakeBuildConcurrencyFlag),
"-scheme", "yass", "-destination", "platform=iOS,name=" + iosTestDeviceNameFlag}
cmdRun(xcodeCmd, true)
} else {
checkCmd := []string{"./yass_test"}
if verboseFlag > 0 {
checkCmd = []string{"./yass_test", "-v", fmt.Sprintf("%d", verboseFlag), "-logtostderr"}
}
cmdRun(checkCmd, true)
}
cmdRun(checkCmd, true)
}
// FIXME move to cmake (required by Xcode generator)
if systemNameFlag == "darwin" {
Expand Down

0 comments on commit fd262a7

Please sign in to comment.