Esempio n. 1
0
//-----------------------------------------------------------------------------
TEST(c_conduit_node, simple_hier)
{
    int     a_val  = 10;
    int     b_val  = 20;
    double  c_val  = 30.0;
    
    conduit_node *n = conduit_node_create();
    
    conduit_node *a = conduit_node_fetch(n,"a");
    conduit_node *b = conduit_node_fetch(n,"b");
    conduit_node *c = conduit_node_fetch(n,"c");

    EXPECT_TRUE(conduit_node_is_root(n));
    
    EXPECT_FALSE(conduit_node_is_root(a));
    EXPECT_FALSE(conduit_node_is_root(b));
    EXPECT_FALSE(conduit_node_is_root(c));
    
    conduit_node_set_int(a,a_val);
    conduit_node_set_int(b,b_val);
    conduit_node_set_double(c,c_val);

    
    EXPECT_EQ(conduit_node_as_int(a),a_val);
    EXPECT_EQ(conduit_node_as_int(b),b_val);
    EXPECT_EQ(conduit_node_as_double(c),c_val);
        
    int    *a_ptr = conduit_node_as_int_ptr(a);
    int    *b_ptr = conduit_node_as_int_ptr(b);
    double *c_ptr = conduit_node_as_double_ptr(c);
    
    EXPECT_EQ(a_ptr[0],a_val);
    EXPECT_EQ(b_ptr[0],b_val);
    EXPECT_EQ(c_ptr[0],c_val);
    
    conduit_node_print(n);
    
    /// these are no-ops
    conduit_node_destroy(a);
    conduit_node_destroy(b);
    conduit_node_destroy(c);

    conduit_node_print(n);
    
    /// this actually deletes the node
    conduit_node_destroy(n);
}
//-----------------------------------------------------------------------------
TEST(conduit_node_set, set_native_float_ptr)
{
    float   fav[4] = {-0.8, -1.6, -3.2, -6.4};
    double  dav[4] = {-0.8, -1.6, -3.2, -6.4};

    conduit_node *n = conduit_node_create();
    
    // float*
    conduit_node_set_float_ptr(n,fav,4);
    conduit_node_print(n);

    float *fav_ptr = conduit_node_as_float_ptr(n);
    for(conduit_index_t i=0;i<4;i++)
    {
        EXPECT_NEAR(fav_ptr[i],fav[i],0.001);
        // set(...) semantics imply a copy -- mem addys should differ
        EXPECT_NE(&fav_ptr[i],&fav[i]); 
    }
    EXPECT_NEAR(fav_ptr[3],-6.4,0.001);
    
    
    // float32 detailed
    conduit_node_set_float_ptr_detailed(n,
                                        fav,
                                        4,
                                        0,
                                        sizeof(float),
                                        sizeof(float),
                                        CONDUIT_ENDIANNESS_DEFAULT_ID);
    conduit_node_print(n);

    fav_ptr = conduit_node_as_float_ptr(n);
    for(conduit_index_t i=0;i<4;i++)
    {
        EXPECT_NEAR(fav_ptr[i],fav[i],0.001);
        // set(...) semantics imply a copy -- mem addys should differ
        EXPECT_NE(&fav_ptr[i],&fav[i]); 
    }
    EXPECT_NEAR(fav_ptr[3],-6.4,0.001);
    
    
    // double
    conduit_node_set_double_ptr(n,dav,4);
    conduit_node_print(n);

    double *dav_ptr = conduit_node_as_double_ptr(n);
    for(conduit_index_t i=0;i<4;i++)
    {
        EXPECT_NEAR(dav_ptr[i],dav[i],0.001);
        // set(...) semantics imply a copy -- mem addys should differ
        EXPECT_NE(&dav_ptr[i],&dav[i]);
    }
    EXPECT_NEAR(dav_ptr[3],-6.4,0.001);

    // float64 detailed
    conduit_node_set_double_ptr_detailed(n,
                                         dav,
                                         4,
                                         0,
                                         sizeof(double),
                                         sizeof(double),
                                         CONDUIT_ENDIANNESS_DEFAULT_ID);
    conduit_node_print(n);

    dav_ptr = conduit_node_as_double_ptr(n);
    for(conduit_index_t i=0;i<4;i++)
    {
        EXPECT_NEAR(dav_ptr[i],dav[i],0.001);
        // set(...) semantics imply a copy -- mem addys should differ
        EXPECT_NE(&dav_ptr[i],&dav[i]);
    }
    EXPECT_NEAR(dav_ptr[3],-6.4,0.001);


    conduit_node_destroy(n);
}