Line data Source code
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 0 : NS_IMPL_ISUPPORTS(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly)
10 :
11 0 : xpcTestObjectReadOnly :: xpcTestObjectReadOnly() {
12 0 : boolProperty = true;
13 0 : shortProperty = 32767;
14 0 : longProperty = 2147483647;
15 0 : floatProperty = 5.5f;
16 0 : charProperty = 'X';
17 : // timeProperty is PRTime and signed type.
18 : // So it has to allow negative value.
19 0 : timeProperty = -1;
20 0 : }
21 :
22 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetStrReadOnly(char * *aStrReadOnly){
23 0 : char aString[] = "XPConnect Read-Only String";
24 :
25 0 : if (!aStrReadOnly)
26 0 : return NS_ERROR_NULL_POINTER;
27 0 : *aStrReadOnly = (char*) nsMemory::Clone(aString,
28 0 : sizeof(char)*(strlen(aString)+1));
29 0 : return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
30 : }
31 :
32 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetBoolReadOnly(bool* aBoolReadOnly) {
33 0 : *aBoolReadOnly = boolProperty;
34 0 : return NS_OK;
35 : }
36 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetShortReadOnly(int16_t* aShortReadOnly){
37 0 : *aShortReadOnly = shortProperty;
38 0 : return NS_OK;
39 : }
40 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetLongReadOnly(int32_t* aLongReadOnly){
41 0 : *aLongReadOnly = longProperty;
42 0 : return NS_OK;
43 : }
44 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetFloatReadOnly(float* aFloatReadOnly){
45 0 : *aFloatReadOnly = floatProperty;
46 0 : return NS_OK;
47 : }
48 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetCharReadOnly(char* aCharReadOnly){
49 0 : *aCharReadOnly = charProperty;
50 0 : return NS_OK;
51 : }
52 0 : NS_IMETHODIMP xpcTestObjectReadOnly :: GetTimeReadOnly(PRTime* aTimeReadOnly){
53 0 : *aTimeReadOnly = timeProperty;
54 0 : return NS_OK;
55 : }
56 :
57 0 : NS_IMPL_ISUPPORTS(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite)
58 :
59 0 : xpcTestObjectReadWrite :: xpcTestObjectReadWrite() {
60 0 : const char s[] = "XPConnect Read-Writable String";
61 0 : stringProperty = (char*) nsMemory::Clone(s, sizeof(char)*(strlen(s)+1));
62 0 : boolProperty = true;
63 0 : shortProperty = 32767;
64 0 : longProperty = 2147483647;
65 0 : floatProperty = 5.5f;
66 0 : charProperty = 'X';
67 : // timeProperty is PRTime and signed type.
68 : // So it has to allow negative value.
69 0 : timeProperty = -1;
70 0 : }
71 :
72 0 : xpcTestObjectReadWrite :: ~xpcTestObjectReadWrite()
73 : {
74 0 : free(stringProperty);
75 0 : }
76 :
77 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetStringProperty(char * *aStringProperty) {
78 0 : if (!aStringProperty)
79 0 : return NS_ERROR_NULL_POINTER;
80 0 : *aStringProperty = (char*) nsMemory::Clone(stringProperty,
81 0 : sizeof(char)*(strlen(stringProperty)+1));
82 0 : return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
83 :
84 : }
85 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) {
86 0 : free(stringProperty);
87 0 : stringProperty = (char*) nsMemory::Clone(aStringProperty,
88 0 : sizeof(char)*(strlen(aStringProperty)+1));
89 0 : return NS_OK;
90 : }
91 :
92 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetBooleanProperty(bool* aBooleanProperty) {
93 0 : *aBooleanProperty = boolProperty;
94 0 : return NS_OK;
95 : }
96 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetBooleanProperty(bool aBooleanProperty) {
97 0 : boolProperty = aBooleanProperty;
98 0 : return NS_OK;
99 : }
100 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetShortProperty(int16_t* aShortProperty) {
101 0 : *aShortProperty = shortProperty;
102 0 : return NS_OK;
103 : }
104 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetShortProperty(int16_t aShortProperty) {
105 0 : shortProperty = aShortProperty;
106 0 : return NS_OK;
107 : }
108 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetLongProperty(int32_t* aLongProperty) {
109 0 : *aLongProperty = longProperty;
110 0 : return NS_OK;
111 : }
112 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetLongProperty(int32_t aLongProperty) {
113 0 : longProperty = aLongProperty;
114 0 : return NS_OK;
115 : }
116 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetFloatProperty(float* aFloatProperty) {
117 0 : *aFloatProperty = floatProperty;
118 0 : return NS_OK;
119 : }
120 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetFloatProperty(float aFloatProperty) {
121 0 : floatProperty = aFloatProperty;
122 0 : return NS_OK;
123 : }
124 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetCharProperty(char* aCharProperty) {
125 0 : *aCharProperty = charProperty;
126 0 : return NS_OK;
127 : }
128 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetCharProperty(char aCharProperty) {
129 0 : charProperty = aCharProperty;
130 0 : return NS_OK;
131 : }
132 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: GetTimeProperty(PRTime* aTimeProperty) {
133 0 : *aTimeProperty = timeProperty;
134 0 : return NS_OK;
135 : }
136 0 : NS_IMETHODIMP xpcTestObjectReadWrite :: SetTimeProperty(PRTime aTimeProperty) {
137 0 : timeProperty = aTimeProperty;
138 0 : return NS_OK;
139 : }
|