1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/components/native/xpctest_attributes.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "xpctest_private.h" 1.11 + 1.12 +NS_IMPL_ISUPPORTS(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly) 1.13 + 1.14 +xpcTestObjectReadOnly :: xpcTestObjectReadOnly() { 1.15 + boolProperty = true; 1.16 + shortProperty = 32767; 1.17 + longProperty = 2147483647; 1.18 + floatProperty = 5.5f; 1.19 + charProperty = 'X'; 1.20 + // timeProperty is PRTime and signed type. 1.21 + // So it has to allow negative value. 1.22 + timeProperty = -1; 1.23 +} 1.24 + 1.25 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetStrReadOnly(char * *aStrReadOnly){ 1.26 + char aString[] = "XPConnect Read-Only String"; 1.27 + 1.28 + if (!aStrReadOnly) 1.29 + return NS_ERROR_NULL_POINTER; 1.30 + *aStrReadOnly = (char*) nsMemory::Clone(aString, 1.31 + sizeof(char)*(strlen(aString)+1)); 1.32 + return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 1.33 +} 1.34 + 1.35 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetBoolReadOnly(bool *aBoolReadOnly) { 1.36 + *aBoolReadOnly = boolProperty; 1.37 + return NS_OK; 1.38 +} 1.39 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetShortReadOnly(int16_t *aShortReadOnly){ 1.40 + *aShortReadOnly = shortProperty; 1.41 + return NS_OK; 1.42 +} 1.43 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetLongReadOnly(int32_t *aLongReadOnly){ 1.44 + *aLongReadOnly = longProperty; 1.45 + return NS_OK; 1.46 +} 1.47 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetFloatReadOnly(float *aFloatReadOnly){ 1.48 + *aFloatReadOnly = floatProperty; 1.49 + return NS_OK; 1.50 +} 1.51 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetCharReadOnly(char *aCharReadOnly){ 1.52 + *aCharReadOnly = charProperty; 1.53 + return NS_OK; 1.54 +} 1.55 +NS_IMETHODIMP xpcTestObjectReadOnly :: GetTimeReadOnly(PRTime *aTimeReadOnly){ 1.56 + *aTimeReadOnly = timeProperty; 1.57 + return NS_OK; 1.58 +} 1.59 + 1.60 +NS_IMPL_ISUPPORTS(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite) 1.61 + 1.62 +xpcTestObjectReadWrite :: xpcTestObjectReadWrite() { 1.63 + const char s[] = "XPConnect Read-Writable String"; 1.64 + stringProperty = (char*) nsMemory::Clone(s, sizeof(char)*(strlen(s)+1)); 1.65 + boolProperty = true; 1.66 + shortProperty = 32767; 1.67 + longProperty = 2147483647; 1.68 + floatProperty = 5.5f; 1.69 + charProperty = 'X'; 1.70 + // timeProperty is PRTime and signed type. 1.71 + // So it has to allow negative value. 1.72 + timeProperty = -1; 1.73 +} 1.74 + 1.75 +xpcTestObjectReadWrite :: ~xpcTestObjectReadWrite() 1.76 +{ 1.77 + nsMemory::Free(stringProperty); 1.78 +} 1.79 + 1.80 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetStringProperty(char * *aStringProperty) { 1.81 + if (!aStringProperty) 1.82 + return NS_ERROR_NULL_POINTER; 1.83 + *aStringProperty = (char*) nsMemory::Clone(stringProperty, 1.84 + sizeof(char)*(strlen(stringProperty)+1)); 1.85 + return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 1.86 + 1.87 +} 1.88 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) { 1.89 + nsMemory::Free(stringProperty); 1.90 + stringProperty = (char*) nsMemory::Clone(aStringProperty, 1.91 + sizeof(char)*(strlen(aStringProperty)+1)); 1.92 + return NS_OK; 1.93 +} 1.94 + 1.95 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetBooleanProperty(bool *aBooleanProperty) { 1.96 + *aBooleanProperty = boolProperty; 1.97 + return NS_OK; 1.98 +} 1.99 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetBooleanProperty(bool aBooleanProperty) { 1.100 + boolProperty = aBooleanProperty; 1.101 + return NS_OK; 1.102 +} 1.103 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetShortProperty(int16_t *aShortProperty) { 1.104 + *aShortProperty = shortProperty; 1.105 + return NS_OK; 1.106 +} 1.107 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetShortProperty(int16_t aShortProperty) { 1.108 + shortProperty = aShortProperty; 1.109 + return NS_OK; 1.110 +} 1.111 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetLongProperty(int32_t *aLongProperty) { 1.112 + *aLongProperty = longProperty; 1.113 + return NS_OK; 1.114 +} 1.115 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetLongProperty(int32_t aLongProperty) { 1.116 + longProperty = aLongProperty; 1.117 + return NS_OK; 1.118 +} 1.119 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetFloatProperty(float *aFloatProperty) { 1.120 + *aFloatProperty = floatProperty; 1.121 + return NS_OK; 1.122 +} 1.123 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetFloatProperty(float aFloatProperty) { 1.124 + floatProperty = aFloatProperty; 1.125 + return NS_OK; 1.126 +} 1.127 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetCharProperty(char *aCharProperty) { 1.128 + *aCharProperty = charProperty; 1.129 + return NS_OK; 1.130 +} 1.131 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetCharProperty(char aCharProperty) { 1.132 + charProperty = aCharProperty; 1.133 + return NS_OK; 1.134 +} 1.135 +NS_IMETHODIMP xpcTestObjectReadWrite :: GetTimeProperty(PRTime *aTimeProperty) { 1.136 + *aTimeProperty = timeProperty; 1.137 + return NS_OK; 1.138 +} 1.139 +NS_IMETHODIMP xpcTestObjectReadWrite :: SetTimeProperty(PRTime aTimeProperty) { 1.140 + timeProperty = aTimeProperty; 1.141 + return NS_OK; 1.142 +}