Skip to content

Commit

Permalink
write LongLS output to file
Browse files Browse the repository at this point in the history
  • Loading branch information
efu39 committed Apr 14, 2020
1 parent f61c5f8 commit 8d3c2b1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Jenkinsfiles/mac
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ pipeline {
}

sh '''
mkdir -p testoutput
echo "Build OSXScraper..."
cd osxscraper
xcodebuild -list -project OSXScraper.xcodeproj
xcodebuild -scheme OSXScraper build
ls -lht ../testoutput/
echo "Build OSXProxy..."
cd ../osxproxy
Expand Down Expand Up @@ -47,7 +49,7 @@ pipeline {
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
echo "test-without-building, run 1 case to enable Accessibility access magically"
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper -only-testing:OSXScraperTests/OSXScrapperTests/test001LS
xcodebuild test-without-building -project OSXScraper.xcodeproj -scheme OSXScraper -only-testing:OSXScraperTests/OSXScrapperTests/test001_LS_Self
echo "enable the allow access in TCC.db"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'select * from access'
Expand Down
4 changes: 4 additions & 0 deletions osxscraper/OSXScraper/Settings.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
<string>osxsinter.p12</string>
<key>certificate_passcode</key>
<string>123456</string>
<key>xml_logfolder</key>
<string></string>
<key>jenkins_output_dir</key>
<string>/Users/jenkins/workspace/sinter-mac/testoutput</string>
</dict>
</plist>
62 changes: 56 additions & 6 deletions osxscraper/OSXScraperTests/OSXScraperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "Config.h"
#import "XMLTags.h"
#import "Scraper.h"
#import "Serializer.h"


@interface OSXScrapperTests : XCTestCase
Expand Down Expand Up @@ -70,15 +71,33 @@ - (void)tearDown

}

- (void) test001LS
- (int) exportSinter:(Sinter *) sinter {
NSString * message = [Serializer objectToXml:sinter];
NSDictionary * instanceSetting = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"]];
NSString * logfolder = [instanceSetting objectForKey:@"jenkins_output_dir"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
BOOL isDir;
if ([fileManager fileExistsAtPath:logfolder isDirectory:&isDir] && isDir){
NSString * filename = [NSString stringWithFormat:@"%@/scraper_%@.xml", logfolder, self.name];
NSError * error = NULL;
if([message writeToFile:filename atomically:NO encoding:NSUTF8StringEncoding error:&error])
{
NSLog( @"xml saving to %@", filename);
return 0;
}
}
return -1;
}

- (void) test001_LS_Self
{
//test 'list of applications', should see itself (OSXScraper)
Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]];
Sinter * sinterOutput = [scraper execute:sinterInput];
XCTAssertNotNil(sinterOutput);
XCTAssertTrue([sinterOutput.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsRes]]);
XCTAssertTrue(sinterOutput.entities.count >= 1);

BOOL bFoundSelf = NO;
NSLog(@"%s entities count: %ld", __PRETTY_FUNCTION__, [sinterOutput.entities count]);
for (Entity* e in sinterOutput.entities){
Expand All @@ -90,15 +109,15 @@ - (void) test001LS
XCTAssertTrue(bFoundSelf);
}

- (void) test001LSCalc
- (void) test001_LS_Calc
{
//test 'list of applications', should see itself (OSXScraper)
//test 'list of applications', should see Calculator
Sinter * sinterInput = [[Sinter alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsReq]];
Sinter * sinterOutput = [scraper execute:sinterInput];
XCTAssertNotNil(sinterOutput);
XCTAssertTrue([sinterOutput.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsRes]]);
XCTAssertTrue(sinterOutput.entities.count >= 1);

BOOL bFound = NO;
NSLog(@"%s entities count: %ld", __PRETTY_FUNCTION__, [sinterOutput.entities count]);
for (Entity* e in sinterOutput.entities){
Expand All @@ -110,7 +129,7 @@ - (void) test001LSCalc
XCTAssertTrue(bFound);
}

- (void) test002LongLS
- (void) test002_LongLS_Self
{
// first get the process_id of itself, then test long LS (scrape it and output a response sinter)
Sinter * sinterOutput = [AccAPI getListOfApplications];
Expand All @@ -133,6 +152,37 @@ - (void) test002LongLS
XCTAssertTrue([sinterOutput2.header.process_id isEqualToString:process_id]);
XCTAssertTrue([sinterOutput2.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsLongRes]]);
XCTAssertNotNil(sinterOutput2.entity);
XCTAssertTrue([self exportSinter:sinterOutput2] == 0);
}

- (void) test002_LongLS_Calc
{
// first get the process_id of itself, then test long LS (scrape it and output a response sinter)
Sinter * sinterOutput = [AccAPI getListOfApplications];
NSString* process_id;
for (Entity* e in sinterOutput.entities){
if ([e.name isEqualToString:@"Calculator"]){
NSLog(@"%s %@, %@", __PRETTY_FUNCTION__, e.name, e.process_id);
process_id = e.process_id;
break;
}
}
XCTAssertNotNil(process_id);

// create a sinterInput2 with process_id to test
if (process_id != nil) {
Sinter * sinterInput2 = [[Sinter alloc] init];
sinterInput2.header = [[Header alloc] initWithServiceCode:[serviceCodes objectForKey:STRLsLongReq]
subCode:[serviceCodes objectForKey:STRLsLongReq]
processId:process_id
parameters:nil];
Sinter * sinterOutput2 = [scraper execute:sinterInput2];
XCTAssertNotNil(sinterOutput2);
XCTAssertTrue([sinterOutput2.header.process_id isEqualToString:process_id]);
XCTAssertTrue([sinterOutput2.header.service_code isEqualToNumber: [serviceCodes objectForKey:STRLsLongRes]]);
XCTAssertNotNil(sinterOutput2.entity);
XCTAssertTrue([self exportSinter:sinterOutput2] == 0);
}
}

@end

0 comments on commit 8d3c2b1

Please sign in to comment.