|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "xpctest_private.h" |
|
8 |
|
9 NS_IMPL_ISUPPORTS(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly) |
|
10 |
|
11 xpcTestObjectReadOnly :: xpcTestObjectReadOnly() { |
|
12 boolProperty = true; |
|
13 shortProperty = 32767; |
|
14 longProperty = 2147483647; |
|
15 floatProperty = 5.5f; |
|
16 charProperty = 'X'; |
|
17 // timeProperty is PRTime and signed type. |
|
18 // So it has to allow negative value. |
|
19 timeProperty = -1; |
|
20 } |
|
21 |
|
22 NS_IMETHODIMP xpcTestObjectReadOnly :: GetStrReadOnly(char * *aStrReadOnly){ |
|
23 char aString[] = "XPConnect Read-Only String"; |
|
24 |
|
25 if (!aStrReadOnly) |
|
26 return NS_ERROR_NULL_POINTER; |
|
27 *aStrReadOnly = (char*) nsMemory::Clone(aString, |
|
28 sizeof(char)*(strlen(aString)+1)); |
|
29 return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
|
30 } |
|
31 |
|
32 NS_IMETHODIMP xpcTestObjectReadOnly :: GetBoolReadOnly(bool *aBoolReadOnly) { |
|
33 *aBoolReadOnly = boolProperty; |
|
34 return NS_OK; |
|
35 } |
|
36 NS_IMETHODIMP xpcTestObjectReadOnly :: GetShortReadOnly(int16_t *aShortReadOnly){ |
|
37 *aShortReadOnly = shortProperty; |
|
38 return NS_OK; |
|
39 } |
|
40 NS_IMETHODIMP xpcTestObjectReadOnly :: GetLongReadOnly(int32_t *aLongReadOnly){ |
|
41 *aLongReadOnly = longProperty; |
|
42 return NS_OK; |
|
43 } |
|
44 NS_IMETHODIMP xpcTestObjectReadOnly :: GetFloatReadOnly(float *aFloatReadOnly){ |
|
45 *aFloatReadOnly = floatProperty; |
|
46 return NS_OK; |
|
47 } |
|
48 NS_IMETHODIMP xpcTestObjectReadOnly :: GetCharReadOnly(char *aCharReadOnly){ |
|
49 *aCharReadOnly = charProperty; |
|
50 return NS_OK; |
|
51 } |
|
52 NS_IMETHODIMP xpcTestObjectReadOnly :: GetTimeReadOnly(PRTime *aTimeReadOnly){ |
|
53 *aTimeReadOnly = timeProperty; |
|
54 return NS_OK; |
|
55 } |
|
56 |
|
57 NS_IMPL_ISUPPORTS(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite) |
|
58 |
|
59 xpcTestObjectReadWrite :: xpcTestObjectReadWrite() { |
|
60 const char s[] = "XPConnect Read-Writable String"; |
|
61 stringProperty = (char*) nsMemory::Clone(s, sizeof(char)*(strlen(s)+1)); |
|
62 boolProperty = true; |
|
63 shortProperty = 32767; |
|
64 longProperty = 2147483647; |
|
65 floatProperty = 5.5f; |
|
66 charProperty = 'X'; |
|
67 // timeProperty is PRTime and signed type. |
|
68 // So it has to allow negative value. |
|
69 timeProperty = -1; |
|
70 } |
|
71 |
|
72 xpcTestObjectReadWrite :: ~xpcTestObjectReadWrite() |
|
73 { |
|
74 nsMemory::Free(stringProperty); |
|
75 } |
|
76 |
|
77 NS_IMETHODIMP xpcTestObjectReadWrite :: GetStringProperty(char * *aStringProperty) { |
|
78 if (!aStringProperty) |
|
79 return NS_ERROR_NULL_POINTER; |
|
80 *aStringProperty = (char*) nsMemory::Clone(stringProperty, |
|
81 sizeof(char)*(strlen(stringProperty)+1)); |
|
82 return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
|
83 |
|
84 } |
|
85 NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) { |
|
86 nsMemory::Free(stringProperty); |
|
87 stringProperty = (char*) nsMemory::Clone(aStringProperty, |
|
88 sizeof(char)*(strlen(aStringProperty)+1)); |
|
89 return NS_OK; |
|
90 } |
|
91 |
|
92 NS_IMETHODIMP xpcTestObjectReadWrite :: GetBooleanProperty(bool *aBooleanProperty) { |
|
93 *aBooleanProperty = boolProperty; |
|
94 return NS_OK; |
|
95 } |
|
96 NS_IMETHODIMP xpcTestObjectReadWrite :: SetBooleanProperty(bool aBooleanProperty) { |
|
97 boolProperty = aBooleanProperty; |
|
98 return NS_OK; |
|
99 } |
|
100 NS_IMETHODIMP xpcTestObjectReadWrite :: GetShortProperty(int16_t *aShortProperty) { |
|
101 *aShortProperty = shortProperty; |
|
102 return NS_OK; |
|
103 } |
|
104 NS_IMETHODIMP xpcTestObjectReadWrite :: SetShortProperty(int16_t aShortProperty) { |
|
105 shortProperty = aShortProperty; |
|
106 return NS_OK; |
|
107 } |
|
108 NS_IMETHODIMP xpcTestObjectReadWrite :: GetLongProperty(int32_t *aLongProperty) { |
|
109 *aLongProperty = longProperty; |
|
110 return NS_OK; |
|
111 } |
|
112 NS_IMETHODIMP xpcTestObjectReadWrite :: SetLongProperty(int32_t aLongProperty) { |
|
113 longProperty = aLongProperty; |
|
114 return NS_OK; |
|
115 } |
|
116 NS_IMETHODIMP xpcTestObjectReadWrite :: GetFloatProperty(float *aFloatProperty) { |
|
117 *aFloatProperty = floatProperty; |
|
118 return NS_OK; |
|
119 } |
|
120 NS_IMETHODIMP xpcTestObjectReadWrite :: SetFloatProperty(float aFloatProperty) { |
|
121 floatProperty = aFloatProperty; |
|
122 return NS_OK; |
|
123 } |
|
124 NS_IMETHODIMP xpcTestObjectReadWrite :: GetCharProperty(char *aCharProperty) { |
|
125 *aCharProperty = charProperty; |
|
126 return NS_OK; |
|
127 } |
|
128 NS_IMETHODIMP xpcTestObjectReadWrite :: SetCharProperty(char aCharProperty) { |
|
129 charProperty = aCharProperty; |
|
130 return NS_OK; |
|
131 } |
|
132 NS_IMETHODIMP xpcTestObjectReadWrite :: GetTimeProperty(PRTime *aTimeProperty) { |
|
133 *aTimeProperty = timeProperty; |
|
134 return NS_OK; |
|
135 } |
|
136 NS_IMETHODIMP xpcTestObjectReadWrite :: SetTimeProperty(PRTime aTimeProperty) { |
|
137 timeProperty = aTimeProperty; |
|
138 return NS_OK; |
|
139 } |