mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-27 13:40:37 -10:00
This patch was generated by a script. Here's the source of the script for
future reference:
function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
! -wholename "*security/nss*" \
! -wholename "*/.hg*" \
! -wholename "obj-ff-dbg*" \
! -name nsXPCOMCID.h \
! -name prtypes.h \
-type f \
\( -iname "*.cpp" \
-o -iname "*.h" \
-o -iname "*.c" \
-o -iname "*.cc" \
-o -iname "*.idl" \
-o -iname "*.ipdl" \
-o -iname "*.ipdlh" \
-o -iname "*.mm" \) | \
xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}
convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t
convert PRIntn int
convert PRUintn unsigned
convert PRSize size_t
convert PROffset32 int32_t
convert PROffset64 int64_t
convert PRPtrdiff ptrdiff_t
convert PRFloat64 double
142 lines
4.1 KiB
C++
142 lines
4.1 KiB
C++
#include "TestHarness.h"
|
|
|
|
#include "nsISettingsService.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIThread.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "nsDirectoryServiceDefs.h"
|
|
#include "nsDirectoryServiceUtils.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "mozilla/Attributes.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
static int callbackCount = 10;
|
|
static int errors = 0;
|
|
|
|
#define CHECK(x) \
|
|
_doCheck(x, #x, __LINE__)
|
|
|
|
void _doCheck(bool cond, const char* msg, int line) {
|
|
if (cond) return;
|
|
fprintf(stderr, "FAIL: line %d: %s\n", line, msg);
|
|
errors++;
|
|
}
|
|
|
|
typedef nsresult(*TestFuncPtr)();
|
|
|
|
class SettingsServiceCallback MOZ_FINAL : public nsISettingsServiceCallback
|
|
{
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
|
|
SettingsServiceCallback() { }
|
|
|
|
NS_IMETHOD Handle(const nsAString & name, const JS::Value & result, JSContext* cx) {
|
|
if (callbackCount == 9) {
|
|
CHECK(JSVAL_IS_BOOLEAN(result));
|
|
CHECK(JSVAL_TO_BOOLEAN(result) == true);
|
|
passed("boolean");
|
|
} else if (callbackCount == 7) {
|
|
CHECK(JSVAL_IS_BOOLEAN(result));
|
|
CHECK(JSVAL_TO_BOOLEAN(result) == false);
|
|
passed("Lock order");
|
|
} else if (callbackCount == 5) {
|
|
CHECK(JSVAL_IS_INT(result));
|
|
CHECK(JSVAL_TO_INT(result) == 9);
|
|
passed("integer");
|
|
} else if (callbackCount == 3) {
|
|
CHECK(JSVAL_IS_DOUBLE(result));
|
|
CHECK(JSVAL_TO_DOUBLE(result) == 9.4);
|
|
passed("double");
|
|
} else if (callbackCount == 2) {
|
|
CHECK(JSVAL_IS_BOOLEAN(result));
|
|
CHECK(JSVAL_TO_BOOLEAN(result) == false);
|
|
passed("Lock order");
|
|
} else if (callbackCount == 1) {
|
|
passed("null");
|
|
CHECK(JSVAL_IS_NULL(result));
|
|
}
|
|
callbackCount--;
|
|
return NS_OK;
|
|
};
|
|
|
|
NS_IMETHOD HandleError(const nsAString & name, JSContext* cx) {
|
|
fprintf(stderr, "HANDLE Error! %s\n", NS_LossyConvertUTF16toASCII(name).get());
|
|
errors++;
|
|
return NS_OK;
|
|
};
|
|
};
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(SettingsServiceCallback, nsISettingsServiceCallback)
|
|
|
|
nsresult
|
|
TestSettingsAPI()
|
|
{
|
|
nsresult rv;
|
|
nsCOMPtr<nsISettingsService> settingsService = do_CreateInstance("@mozilla.org/settingsService;1", &rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsISettingsServiceCallback> cb0 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb1 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb2 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb3 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb4 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb5 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb6 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb7 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb8 = new SettingsServiceCallback();
|
|
nsCOMPtr<nsISettingsServiceCallback> cb9 = new SettingsServiceCallback();
|
|
|
|
nsCOMPtr<nsISettingsService> iss = do_GetService("@mozilla.org/settingsService;1");
|
|
nsCOMPtr<nsISettingsServiceLock> lock;
|
|
iss->GetLock(getter_AddRefs(lock));
|
|
|
|
nsCOMPtr<nsISettingsServiceLock> lock1;
|
|
iss->GetLock(getter_AddRefs(lock1));
|
|
|
|
lock->Set("asdf", BOOLEAN_TO_JSVAL(true), cb0);
|
|
lock1->Get("asdf", cb1);
|
|
lock->Get("asdf", cb2);
|
|
lock->Set("asdf", BOOLEAN_TO_JSVAL(false), cb3);
|
|
lock->Get("asdf", cb4);
|
|
lock->Set("int", INT_TO_JSVAL(9), cb5);
|
|
lock->Get("int", cb6);
|
|
lock->Set("doub", DOUBLE_TO_JSVAL(9.4), cb7);
|
|
lock->Get("doub", cb8);
|
|
lock1->Get("asdfxxx", cb9);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
passed("Start TestSettingsAPI");
|
|
ScopedXPCOM xpcom("TestSettingsAPI");
|
|
nsCOMPtr<nsIProperties> os =
|
|
do_GetService("@mozilla.org/file/directory_service;1");
|
|
if (!os) {
|
|
fprintf(stderr, "DIRSERVICE NULL!!!!!!\n");
|
|
return 1;
|
|
}
|
|
|
|
NS_ENSURE_FALSE(xpcom.failed(), 1);
|
|
|
|
static TestFuncPtr testsToRun[] = {
|
|
TestSettingsAPI
|
|
};
|
|
static uint32_t testCount = sizeof(testsToRun) / sizeof(testsToRun[0]);
|
|
|
|
for (uint32_t i = 0; i < testCount; i++) {
|
|
nsresult rv = testsToRun[i]();
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
}
|
|
nsCOMPtr<nsIThread> current(do_GetCurrentThread());
|
|
while (callbackCount > 0)
|
|
NS_ProcessNextEvent(current);
|
|
|
|
passed("END!");
|
|
return errors;
|
|
}
|