summaryrefslogtreecommitdiffstats
path: root/tests/syntax-tests/source/Objective-C++/test.mm
diff options
context:
space:
mode:
authorhenil <dedaniahenil@gmail.com>2020-11-15 00:22:08 +0530
committerDavid Peter <sharkdp@users.noreply.github.com>2020-11-23 15:43:58 +0100
commit591eba66a3af1c211a09eefd17cbeb819b0a131f (patch)
treecf0b604f97314d567745498c85be1aec36e85f25 /tests/syntax-tests/source/Objective-C++/test.mm
parenta5a9ac83e5a506ac2bdc673476aca54c818eabe2 (diff)
add new syntax test filesv0.17.0
Diffstat (limited to 'tests/syntax-tests/source/Objective-C++/test.mm')
-rw-r--r--tests/syntax-tests/source/Objective-C++/test.mm68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/syntax-tests/source/Objective-C++/test.mm b/tests/syntax-tests/source/Objective-C++/test.mm
new file mode 100644
index 00000000..6f8663fb
--- /dev/null
+++ b/tests/syntax-tests/source/Objective-C++/test.mm
@@ -0,0 +1,68 @@
+#import <Foundation/Foundation.h>
+
+class Hello {
+ private:
+ id greeting_text;
+
+ public:
+ Hello() {
+ greeting_text = @"Hello, world!";
+ }
+
+ Hello(const char* initial_greeting_text) {
+ greeting_text = [[NSString alloc] initWithUTF8String:initial_greeting_text];
+ }
+
+ void say_hello() {
+ printf("%s\n", [greeting_text UTF8String]);
+ }
+};
+
+@interface Greeting : NSObject {
+ @private
+ Hello *hello;
+
+}
+- (id)init;
+- (void)dealloc;
+- (void)sayGreeting;
+- (void)sayGreeting:(Hello*)greeting;
+@end
+
+@implementation Greeting
+- (id)init {
+ self = [super init];
+ if (self) {
+ hello = new Hello();
+ }
+ return self;
+}
+
+- (void)dealloc {
+ delete hello;
+ [super dealloc];
+}
+
+- (void)sayGreeting {
+ hello->say_hello();
+}
+
+- (void)sayGreeting:(Hello*)greeting {
+ greeting->say_hello();
+}
+@end
+
+int main() {
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ Greeting *greeting = [[Greeting alloc] init];
+ [greeting sayGreeting];
+
+ Hello *hello = new Hello("Bonjour, monde!");
+ [greeting sayGreeting:hello];
+
+ delete hello;
+ [greeting release];
+ [pool release];
+ return 0;
+}