Commit c5aaadc4 authored by Dan Hipschman's avatar Dan Hipschman Committed by Alexandre Julliard

widl: Lay framework for unions with simple unions working.

parent 18724eae
......@@ -21,6 +21,7 @@
#include <windows.h>
#include "wine/test.h"
#include "server.h"
#include "server_defines.h"
#include <stdio.h>
......@@ -138,6 +139,19 @@ s_sum_sp(sp_t *sp)
return sp->x + sp->s->x;
}
double
s_square_sun(sun_t *sun)
{
switch (sun->s)
{
case SUN_I: return sun->u.i * sun->u.i;
case SUN_F1:
case SUN_F2: return sun->u.f * sun->u.f;
default:
return 0.0;
}
}
void
s_stop(void)
{
......@@ -253,6 +267,24 @@ basic_tests(void)
}
static void
union_tests(void)
{
sun_t sun;
sun.s = SUN_I;
sun.u.i = 9;
ok(square_sun(&sun) == 81.0, "RPC square_sun\n");
sun.s = SUN_F1;
sun.u.f = 5.0;
ok(square_sun(&sun) == 25.0, "RPC square_sun\n");
sun.s = SUN_I;
sun.u.i = -2.0;
ok(square_sun(&sun) == 4.0, "RPC square_sun\n");
}
static void
client(const char *test)
{
if (strcmp(test, "tcp_basic") == 0)
......@@ -266,6 +298,7 @@ client(const char *test)
ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
basic_tests();
union_tests();
ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
......@@ -281,6 +314,7 @@ client(const char *test)
ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
basic_tests();
union_tests();
stop();
ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
......
......@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "server_defines.h"
typedef struct tag_vector
{
int x;
......@@ -53,6 +55,17 @@ interface IServer
vector_t **pv;
} pvectors_t;
typedef struct
{
[switch_is(s)] union
{
[case(SUN_I)] int i;
[case(SUN_F1, SUN_F2)] float f;
} u;
int s;
} sun_t;
int int_return(void);
int square(int x);
int sum(int x, int y);
......@@ -81,5 +94,6 @@ interface IServer
} sp_t;
int sum_sp(sp_t *sp);
double square_sun(sun_t *sun);
void stop(void);
}
/*
* Constants shared between server.c and server.idl
*
* Copyright (C) Google 2007 (Dan Hipschman)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* sun_t case values */
#define SUN_I 10
#define SUN_F1 -2
#define SUN_F2 7
......@@ -1260,6 +1260,7 @@ static var_t *make_var(char *name)
v->attrs = NULL;
v->array = NULL;
v->eval = NULL;
v->corrdesc = 0;
return v;
}
......
......@@ -220,6 +220,7 @@ struct _var_t {
var_list_t *args; /* for function pointers */
attr_list_t *attrs;
expr_t *eval;
size_t corrdesc; /* offset to correlation descriptor (e.g., for unions) */
/* parser-internal */
struct list entry;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment