forked from Blendman974/faceclaw
iOS porting: Config pull and push scripts; Terminal works; voice input with Siri works
This commit is contained in:
1 parent
b07ae0b479
commit
319d3dc44b
21 files changed
+339
-9
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FaceclawConfigPort.h"
|
||||
#include <assert.h>
|
||||
static NSDictionary *send(NSString *dir, NSUserDefaults *defaults, NSString *domain, NSDictionary *request) {
|
||||
NSData *json = [NSJSONSerialization dataWithJSONObject:request options:0 error:nil];
|
||||
assert([json writeToFile:[dir stringByAppendingPathComponent:@"request.json"] atomically:YES]);
|
||||
[FaceclawConfigPort processDirectory:dir defaults:defaults domain:domain];
|
||||
assert(![NSFileManager.defaultManager fileExistsAtPath:[dir stringByAppendingPathComponent:@"request.json"]]);
|
||||
return [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[dir stringByAppendingPathComponent:@"response.json"]] options:0 error:nil];
|
||||
}
|
||||
int main(int argc, const char **argv) { @autoreleasepool {
|
||||
NSString *dir = [NSString stringWithUTF8String:argv[1]];
|
||||
NSString *domain = [@"com.faceclaw.config-test." stringByAppendingString:NSUUID.UUID.UUIDString];
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:domain];
|
||||
[defaults setPersistentDomain:@{@"keep":@"original", @"enabled":@NO} forName:domain];
|
||||
NSDictionary *input = @{@"terminal.connections":@"[{\"url\":\"g2mirror://test@host\"}]", @"enabled":@YES, @"empty":@"", @"number":@42, @"unicode":@"π & < \n 🔋"};
|
||||
NSDictionary *reply = send(dir, defaults, domain, @{@"id":@"1", @"operation":@"push", @"settings":input});
|
||||
assert([reply[@"ok"] boolValue] && [reply[@"count"] intValue] == 5);
|
||||
assert([[defaults persistentDomainForName:domain][@"keep"] isEqual:@"original"]);
|
||||
NSDictionary *backup = [NSDictionary dictionaryWithContentsOfFile:[dir stringByAppendingPathComponent:@"previous.plist"]];
|
||||
assert([backup[@"keep"] isEqual:@"original"] && ![backup[@"enabled"] boolValue]);
|
||||
reply = send(dir, defaults, domain, @{@"id":@"2", @"operation":@"pull"});
|
||||
assert([reply[@"id"] isEqual:@"2"] && [reply[@"ok"] boolValue]);
|
||||
NSDictionary *output = reply[@"config"][@"settings"];
|
||||
for (NSString *key in input) assert([output[key] isEqual:input[key]]);
|
||||
assert(!output[@"ios.settings.changeToken"]);
|
||||
NSDictionary *before = [defaults persistentDomainForName:domain];
|
||||
reply = send(dir, defaults, domain, @{@"id":@"3", @"operation":@"push", @"settings":@{@"keep":@"changed", @"invalid":@[]}});
|
||||
assert(![reply[@"ok"] boolValue]);
|
||||
assert([[defaults persistentDomainForName:domain] isEqual:before]);
|
||||
reply = send(dir, defaults, domain, @{@"id":@"4", @"operation":@"bad"});
|
||||
assert(![reply[@"ok"] boolValue]);
|
||||
[defaults removePersistentDomainForName:domain]; [defaults synchronize];
|
||||
puts("PASS: native config merges typed values, backs up, exports, consumes requests once and rejects invalid imports atomically");
|
||||
} return 0; }
|
||||
@@ -0,0 +1,28 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FaceclawSpeechTranscript.h"
|
||||
#include <assert.h>
|
||||
static void check(NSString *actual, NSString *expected) { assert([actual isEqual:expected]); }
|
||||
int main(void) { @autoreleasepool {
|
||||
FaceclawSpeechTranscript *t = [FaceclawSpeechTranscript new];
|
||||
check([t updateText:@"How" start:0 duration:0 settled:NO final:NO], @"How");
|
||||
check([t updateText:@"How are you" start:0 duration:0 settled:NO final:NO], @"How are you");
|
||||
check([t updateText:@"How are you?" start:0.5 duration:1.2 settled:YES final:NO], @"How are you?");
|
||||
check([t updateText:@"How are you?" start:0.5 duration:1.2 settled:YES final:NO], @"How are you?");
|
||||
check([t updateText:@"Fine" start:0 duration:0 settled:NO final:NO], @"How are you? Fine");
|
||||
check([t updateText:@"Fine thanks" start:0 duration:0 settled:NO final:NO], @"How are you? Fine thanks");
|
||||
check([t updateText:@"Fine, thanks." start:3 duration:1 settled:YES final:NO], @"How are you? Fine, thanks.");
|
||||
check([t updateText:@"" start:0 duration:0 settled:YES final:NO], @"How are you? Fine, thanks.");
|
||||
check([t updateText:@"Fine, thanks." start:0 duration:0 settled:YES final:YES], @"How are you? Fine, thanks.");
|
||||
// Identical utterances are real repetition, not duplicate callbacks.
|
||||
check([t updateText:@"Fine, thanks." start:0 duration:0 settled:NO final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
check([t updateText:@"Fine, thanks." start:5 duration:1 settled:YES final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
// Some OS/model combinations return cumulative text; retain it once.
|
||||
check([t updateText:@"How are you? Fine, thanks. Fine, thanks." start:0.5 duration:5.5 settled:YES final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
t = [FaceclawSpeechTranscript new];
|
||||
check([t updateText:@"I scream" start:0.5 duration:1 settled:NO final:NO], @"I scream");
|
||||
check([t updateText:@"Ice cream" start:0.5 duration:1.1 settled:NO final:NO], @"Ice cream");
|
||||
check([t updateText:@"Ice cream is good." start:0.5 duration:2 settled:YES final:NO], @"Ice cream is good.");
|
||||
check([t updateText:@"Next sentence" start:4 duration:1 settled:NO final:NO], @"Ice cream is good. Next sentence");
|
||||
check([t updateText:@"Next sentence." start:4 duration:1 settled:YES final:NO], @"Ice cream is good. Next sentence.");
|
||||
puts("PASS: utterance accumulation, live revisions, repeated words, duplicate/cumulative results and empty final callbacks");
|
||||
} return 0; }
|
||||
Reference in new issue
Block a user