adding tests for urp module
author lsv@sparc.spb.su
This commit is contained in:
idk%eng.sun.com 2001-04-10 00:39:05 +00:00
Родитель 94df715357
Коммит 08f286132c
9 изменённых файлов: 548 добавлений и 14 удалений

Просмотреть файл

@ -33,7 +33,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = transport
DIRS = transport test
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
CPPSRCS = \

Просмотреть файл

@ -33,7 +33,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = transport
DIRS = transport test
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
CPPSRCS = \

Просмотреть файл

@ -0,0 +1,71 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Sergey Lunegov <lsv@sparc.spb.su>
DEPTH = ../../../../../
topsrcdir = ../../../../../
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = urpTest
MODULE = urpTest
IS_COMPONENT = 1
XPIDLSRCS = urpITest.idl
PROGRAM = server
CXXFLAGS += -I$(topsrcdir)/java/xpcom/xpcom -I../transport -I$(JDKHOME)/include -I$(topsrcdir)/java/xpcom/java/src -I$(topsrcdir)/java/xpcom/connect/xpcom
CPPSRCS = \
urpTestImpl.cpp \
server.cpp \
$(NULL)
EXTRA_DSO_LIBS += \
bcorb bcxpcomstubs \
$(NULL)
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
../urpStub.o \
../urpManager.o \
../transport/llTransport.o ../transport/urpPacket.o \
../transport/urpTransport.o \
-L../../java/src -lbcjavastubs \
-L$(DIST)/lib/components/ \
EXTRA_DSO_LDOPTS += \
../transport/llTransport.o ../transport/urpPacket.o \
../transport/urpTransport.o \
../urpStub.o \
../urpManager.o \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,67 @@
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsIPref.h"
#include "plevent.h"
#include "prmem.h"
#include "prnetdb.h"
#include "urpManager.h"
#include "urpTransport.h"
#include "urpITest.h"
#include "bcIORBComponent.h"
#include "bcORBComponentCID.h"
#include "urpTestImpl.h"
#include <unistd.h>
#include "nsIModule.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
int main( int argc, char *argv[] ) {
char *connectString = "socket,host=localhost,port=2009";
if( argc == 2 ) connectString = argv[1];
nsresult rv = NS_InitXPCOM(NULL, NULL);
NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &rv);
if (NS_FAILED(rv)) {
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
}
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &rv);
if (NS_FAILED(rv)) {
printf("bcXPCOMStubsAndProxie failed\n");
return -1;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
urpITest *object = new urpTestImpl();
object->AddRef();
urpITest *proxy = NULL;
xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
bcOID oid = orb->RegisterStub(stub);
urpTransport* trans = new urpAcceptor();
PRStatus status = trans->Open(connectString);
if(status == PR_SUCCESS) printf("succes\n");
else printf("failed\n");
object->AddRef();
urpManager* mngr = new urpManager(trans, orb);
rv = NS_OK;
while(NS_SUCCEEDED(rv)) {
rv = mngr->HandleRequest(trans->GetConnection());
}
return 1;
}

Просмотреть файл

@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsISupports.idl"
[scriptable, uuid(bcd584e5-495d-4d2a-aeca-9138040a5f84)]
interface urpITest : nsISupports
{
void test1(inout long l);
void test2(in long l1,inout long l2);
void test3(in string s1,inout string s2);
void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);
void test5(in PRUint32 count,[array, size_is(count)] inout string valueArray);
void test6(in urpITest o);
void test7(out urpITest o);
};

Просмотреть файл

@ -0,0 +1,305 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include "urpTestImpl.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
static char * className = "urpTestImpl";
nsrefcnt urpTestImpl::AddRef(void) {
static const char * methodName="AddRef";
printf("--%s::%s this=%p",className, methodName,this);
nsrefcnt cnt = (nsrefcnt) PR_AtomicIncrement((PRInt32*)&mRefCnt);
return cnt;
}
nsrefcnt urpTestImpl::Release(void) {
static const char * methodName="Release";
nsrefcnt cnt = (nsrefcnt) PR_AtomicDecrement((PRInt32*)&mRefCnt);
printf("--%s::%s this=%p",className, methodName,this);
if(0 == cnt) {
delete this;
}
return cnt;
}
NS_IMETHODIMP urpTestImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
static const char * methodName="QueryInterface";
printf("--%s::%s aIID=%s this=%p",className, methodName,aIID.ToString(),this);
if ( !aInstancePtr ) {
return NS_ERROR_NULL_POINTER;
}
if ( aIID.Equals(NS_GET_IID(nsISupports))
|| aIID.Equals(NS_GET_IID(urpITest)))
{
*(nsISupports**)aInstancePtr = this;
return NS_OK;
} else {
return NS_NOINTERFACE;
}
}
/*void test1(inout long l);*/
NS_IMETHODIMP urpTestImpl::Test1(PRInt32 *l) {
static char * methodName="Test1";
printf("--%s::%s ",className, methodName);
printf("this=%p l=%d\n", this, *l);
*l = 1234;
printf("--%s::%s ",className, methodName);
printf("After l assignment. l=%d\n",*l);
// *_retval = 500;
return NS_OK;
}
/*void test2(in long l1,inout long l2);*/
NS_IMETHODIMP urpTestImpl::Test2(PRInt32 l1, PRInt32* l2) {
static char * methodName="Test2";
printf("this=%p l1=%d l2=%d\n", this, l1, *l2);
*l2 = l1;
printf("--%s::%s ",className, methodName);
printf("After assignment. l1=%d l2=%d\n",l1,*l2);
return NS_OK;
}
/*void test3(in string s1,inout string s2);*/
NS_IMETHODIMP urpTestImpl::Test3(const char *s1, char **s2) {
static char * methodName="Test3";
printf("--%s::%s ",className, methodName);
printf("this=%p s1=%s s2=%s\n",this, s1,*s2);
*s2 = "hi";
printf("--%s::%s ",className, methodName);
printf("After assignment. s2=%s\n",*s2);
return NS_OK;
}
/*void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);*/
NS_IMETHODIMP urpTestImpl::Test4(PRUint32 count, const char **valueArray) {
static char * methodName="Test4";
printf("--%s::%s ",className, methodName);
printf("this=%p count=%d",this, count);
for (unsigned int i = 0; i < count; i++) {
printf("--%s::%s ",className, methodName);
printf("valueArray[%d]=%s\n",i,valueArray[i]);
}
return NS_OK;
}
/*void test5(in PRUint32 count,[array, size_is(count)] inout string valueArray);*/
NS_IMETHODIMP urpTestImpl::Test5(PRUint32 count, char ***valueArray) {
static char * methodName="Test5";
printf("--%s::%s ",className, methodName);
printf("this=%p count=%d\n",this, count);
// char ***value = valueArray;
//printf("value = %p *value = %p **value %p\n",value, *(char***)value,
// **(char***)value);
for (unsigned int i = 0; i < count; i++) {
printf("--%s::%s ",className, methodName);
printf("valueArray[%d]=%s\n",i,(*valueArray)[i]);
}
char ** array = (char **)malloc(sizeof(char*)*4);
array[0] = "1";
array[1] = "2";
array[2] = "hello";
array[3] = "world";
*valueArray = array;
//printf("value = %p *value = %p **value %p\n",value, *(char***)value,
// **(char***)value);
return NS_OK;
}
NS_IMETHODIMP urpTestImpl::Test6(class urpITest *o) {
static const char * methodName="Test6";
printf("--%s::%s ",className, methodName);
printf("this=%p o=%p\n",this, o);
PRInt32 l = 1234;
PRInt32 r;
o->Test1(&l);
return NS_OK;
}
/* void test7 (out urpITest o); */
NS_IMETHODIMP urpTestImpl::Test7(urpITest **o) {
static const char * methodName="Test7";
printf("--%s::%s ",className, methodName);
printf("this=%p *o=%p\n",this,*o);
if (o == NULL) {
return NS_ERROR_NULL_POINTER;
}
*o = new urpTestImpl();
printf("--%s::%s ",className, methodName);
printf("o=%p\n",o);
return NS_OK;
}
/****************************************************/
#include "nsIModule.h"
#include "nsIServiceManager.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
#include "bcIORBComponent.h"
#include "bcORBComponentCID.h"
#include "bcIStub.h"
#include "urpStub.h"
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static void test(void) {
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
bcIID iid = NS_GET_IID(urpITest);
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
printf("zdes ploho\n");
return; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
printf("ne tak zdes\n");
return;
}
nsresult r;
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
printf("--urpTestImpl test failed\n");
return;
}
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--urpTestImpl test failed\n");
return;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
urpITest *object = new urpTestImpl();
object->AddRef();
urpITest *proxy = NULL;
// xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
stub = new urpStub();
printf("yatatatata\n");
bcOID oid = orb->RegisterStub(stub);
printf("---urpTestImpl iid=%s\n",NS_GET_IID(urpITest).ToString());
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(urpITest),orb,(nsISupports**)&proxy);
if (NS_FAILED(r)) {
printf("--urpTestImpl test failed\n");
return;
}
/*******************************************/
char ** valueArray = (char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
PRInt32 l1 = 1999;
PRInt32 ret;
PRInt32 rt;
object->Test1(&l1);
l1 = 1999;
proxy->Test1(&l1);
printf("--urpTestImpl after Test1 l=%d %d\n",l1,ret);
/*******************************************/
PRInt32 l2 = 2000;
l1 = 1999;
proxy->Test2(l1,&l2);
printf("--urpTestImpl after Test2 l2=%d\n",l2);
/*******************************************/
const char * s1 = "s1";
char * s2 = "s2";
proxy->Test3(s1,&s2);
printf("--urpTestImpl after Test3 s2=%s\n",s2);
/*******************************************/
proxy->Test4(4,(const char **)valueArray);
/*******************************************/
char ***valueArray2 = &valueArray;
printf("call object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
object->Test5(4,valueArray2);
printf("after calling object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
valueArray2 = (char ***)&valueArray;
proxy->Test5(4,valueArray2);
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
/*********************************************/
proxy->Test6(object);
/*********************************************/
{
urpITest *p1;
proxy->Test7(&p1);
printf("p1=%p",p1);
PRInt32 l = 1234;
PRInt32 r;
p1->Test1(&l);
urpITest *p3;
printf("--before QueryInterface calling \n");
if (NS_SUCCEEDED(p1->QueryInterface(NS_GET_IID(urpITest),(void**)&p3))) {
l=2000;
p3->Test1(&l);
}
}
}
static int counter = 0; //we do not need to call it on unload time;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
nsIFile *location,
nsIModule** result) //I am using it for runnig test *only*
{
if (counter == 0) {
counter ++;
test();
}
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __urpTestImpl_h
#define __urpTestImpl_h
#include "urpITest.h"
class urpTestImpl : public urpITest {
NS_DECL_ISUPPORTS
urpTestImpl() {
NS_INIT_REFCNT();
}
/*void test1(inout long l);*/
NS_IMETHOD Test1(PRInt32 *l);
/*void test2(in long l1,inout long l2);*/
NS_IMETHOD Test2(PRInt32 l1, PRInt32* l2);
/*void test3(in string s1,inout string s2);*/
NS_IMETHOD Test3(const char *s1, char **s2);
/*void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);*/
NS_IMETHOD Test4(PRUint32 count, const char **valueArray);
/*void test5(in PRUint32 count,[array, size_is(count)] inout string valueArray);*/
NS_IMETHOD Test5(PRUint32 count, char ***valueArray);
/*void test6(in urpITest o);*/
NS_IMETHOD Test6(class urpITest *o);
/* void test7 (out urpITest o); */
NS_IMETHOD Test7(urpITest **o);
};
#endif /* __urpTestImpl_h */

Просмотреть файл

@ -145,7 +145,6 @@ void
urpManager::WriteType(bcIID iid, urpPacket* message) {
short cache_index;
printf("IID %s\n",iid.ToString());
char typeClass = INTERFACE;
int found = 0;
@ -165,8 +164,11 @@ printf("write type is %x\n",(char)typeClass | (found ? 0x0 : 0x80));
message->WriteShort(cache_index);
printf("write type is %x\n",cache_index);
if(!found)
message->WriteString(iid.ToString(), strlen(iid.ToString()));
if(!found) {
char* iidStr = iid.ToString();
message->WriteString(iidStr, strlen(iidStr));
PR_Free(iidStr);
}
}
}
@ -182,6 +184,7 @@ urpManager::ReadType(urpPacket* message) {
nsIID iid;
char* name = message->ReadString(size);
iid.Parse(name);
PR_Free(name);
return iid;
}
@ -207,10 +210,13 @@ urpManager::WriteOid(bcOID oid, urpPacket* message) {
bcOID
urpManager::ReadOid(urpPacket* message) {
int& size = 0;
bcOID result;
char* str = message->ReadString(size);
short cache_index = message->ReadShort();
return (bcOID)atol(str);
result = (bcOID)atol(str);
PR_Free(str);
return result;
}
void
@ -234,10 +240,12 @@ urpManager::WriteThreadID(bcTID tid, urpPacket* message) {
bcTID
urpManager::ReadThreadID(urpPacket* message) {
int& size = 0;
bcTID result;
char* array = message->ReadOctetStream(size);
short cache_index = message->ReadShort();
return (bcTID)array[0];
result= (bcTID)array[0];
PR_Free(array);
return result;
}
nsresult
@ -352,7 +360,6 @@ printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return r;
}
printf("arraySize %d %d\n",arraySize,(int)&arraySize);
message->WriteInt(arraySize);
PRInt16 elemSize = GetSimpleSize(datumType);
char *current = *(char**)data;
@ -394,7 +401,6 @@ urpManager::WriteParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTM
nsXPTCVariant *value = & params[i];
void *data;
data = (isOut) ? value->val.p : value;
printf("before Marshal %d %d %d %d\n",methodIndex,paramCount,i,param.GetType().TagPart());
rv = MarshalElement(data, &param,param.GetType().TagPart(), i, interfaceInfo, message, methodIndex, info, params);
if(NS_FAILED(rv)) return rv;
@ -504,7 +510,6 @@ printf("NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xp failed\n");
PRUint32 arraySize;
PRInt16 elemSize = GetSimpleSize(datumType);
arraySize = message->ReadInt();
printf("arraySize is %d\n",arraySize);
char * current;
*(char**)data = current = (char *) allocator->Alloc(elemSize*arraySize);
@ -547,7 +552,6 @@ urpManager::ReadParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMe
void *data;
data = (isOut) ? value->val.p : value;
printf("before UnMarshal %d %d %d %d\n",methodIndex,paramCount,i,param.GetType().TagPart());
rv = UnMarshal(data, &param, param.GetType().TagPart(), interfaceInfo,
message, methodIndex, allocator);
if(NS_FAILED(rv)) return rv;
@ -573,7 +577,7 @@ printf("before UnMarshal %d %d %d %d\n",methodIndex,paramCount,i,param.GetType()
}
*/
}
free(allocator);
delete allocator;
return rv;
}
@ -594,6 +598,7 @@ printf("header in reply is %x %x %x\n",header, BIG_HEADER, header & BIG_HEADER);
else
printf("short request header\n");
delete connection;
delete message;
// transport->close();
return rv;
}

Просмотреть файл

@ -54,7 +54,6 @@ void urpStub::Dispatch(bcICall *call) {
printf("this is method Dispatch of urpStub\n");
bcIID iid; bcOID oid; bcMID mid;
call->GetParams(&iid, &oid, &mid);
printf("IID %s %ld %ld\n",iid.ToString(),oid,mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {