示例#1
0
文件: test.cpp 项目: djacobow/djs
int tests_1() {
 const int TSTRL = 128;
 char tdata[2048];
 char tstr[TSTRL];
 int fc = 0;
 bool ok = false;
 djs_tok_t res, r3;
 int aryLen = 0;

 loadFile(tdata,"inputs/example.json");

 djs_tok_t whole = djs_createFrom(tdata);

 fc += eT(ok = djs_findNamed(&whole, "this", &res));
 fc += eT(ok = djs_getStr(&res,tstr,TSTRL));
 fc += eS(tstr,"that");
 fc += eT(ok = djs_findNamed(&whole,"other",&res));
 djs_tok_t res2;
 fc += eT(ok = djs_findNamed(&res,"this",&res2));
 fc += eT(ok = djs_getStr(&res2,tstr,TSTRL));
 fc += eS(tstr,"notthat");
 fc += eT(ok = djs_findNamed(&res,"smelly",&res2));
 bool smelly = false;
 fc += eT(ok = djs_getBool(&res2,&smelly));
 fc += eT(smelly);
 fc += eT(ok = djs_findNamed(&res,"ugly",&res2));
 bool ugly = true;
 fc += eT(ok = djs_getBool(&res2,&ugly));
 fc += eF(ugly);
 fc += eT(ok = djs_findNamed(&whole,"boo",&res));
 fc += eI(aryLen = djs_getLength(&res),6);
 bool intables[] = { true, true, false, true, false, true };
 int  tvals[]    = { 11, 222, -1, 3333, -1, 55 };
 for (int i=0;i<aryLen;i++) {
  djs_tok_t r2;
  fc += eT(ok = djs_findIndex(&res,i,&r2));
  int ival;
  fc += eI(djs_getInt(&r2,&ival),intables[i]);
  if (intables[i]) {
   fc += eI(ival, tvals[i]);
  }
 }

 fc += eT(ok = djs_findNamed(&whole,"poop",&res));
 fc += eT(ok = djs_findIndex(&res,2,&r3));
 fc += eT(ok = djs_getStr(&r3,tstr,TSTRL));
 fc += eS(tstr, 
   "{ \"in\": 2, \"st\": 333333, \"rs\": [ 3,3,3,3,3,3 ] }");

 if (fc) {
  printf("---- FAIL with %d errors ----\n",fc);
 }

 return fc;
};
示例#2
0
文件: test.cpp 项目: djacobow/djs
int tests_2() {
 const char td1[] = "{}";
 const char td2[] = "[]";
 int fc = 0;

 djs_tok_t w1 = djs_createFrom(td1);
 djs_tok_t w2 = djs_createFrom(td2);
 djs_tok_t res;
 bool ok = 0;

 fc += eT(djs_valid(&w1));
 fc += eT(djs_valid(&w2));
 fc += eI(djs_getLength(&w2),0);
 fc += eF(ok = djs_findNamed(&w1,"bob",&res));
 fc += eF(ok = djs_findNamed(&w1,"",&res));
 fc += eF(ok = djs_findIndex(&w2,0,&res));
 fc += eF(ok = djs_findIndex(&w2,1,&res));

 return fc;
};
示例#3
0
文件: test.cpp 项目: djacobow/djs
int tests_5() {

 const char td[] = "[[[[[]]]]]";
 djs_tok_t w = djs_createFrom(td);
 int fc = 0;

 fc += eT(djs_valid(&w));
 djs_tok_t a,b,c,d,e;
 bool ok; 
 fc += eT(ok = djs_findIndex(&w,0,&a));
 fc += eT(ok = djs_findIndex(&a,0,&b));
 fc += eT(ok = djs_findIndex(&b,0,&c));
 fc += eT(ok = djs_findIndex(&c,0,&d));
 fc += eF(ok = djs_findIndex(&d,0,&e));
 return fc;
};
示例#4
0
void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
{
  if ( myShape.IsSame( aSh ))
    return;

  myShape = aSh;
  mySeamShapeIds.clear();
  myDegenShapeIds.clear();

  if ( myShape.IsNull() ) {
    myShapeID  = -1;
    return;
  }
  SMESHDS_Mesh* meshDS = GetMeshDS();
  myShapeID = meshDS->ShapeToIndex(aSh);

  // treatment of periodic faces
  for ( TopExp_Explorer eF( aSh, TopAbs_FACE ); eF.More(); eF.Next() )
  {
    const TopoDS_Face& face = TopoDS::Face( eF.Current() );
    BRepAdaptor_Surface surface( face );
    if ( surface.IsUPeriodic() || surface.IsVPeriodic() )
    {
      for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next())
      {
        // look for a seam edge
        const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
        if ( BRep_Tool::IsClosed( edge, face )) {
          // initialize myPar1, myPar2 and myParIndex
          if ( mySeamShapeIds.empty() ) {
            gp_Pnt2d uv1, uv2;
            BRep_Tool::UVPoints( edge, face, uv1, uv2 );
            if ( Abs( uv1.Coord(1) - uv2.Coord(1) ) < Abs( uv1.Coord(2) - uv2.Coord(2) ))
            {
              myParIndex = 1; // U periodic
              myPar1 = surface.FirstUParameter();
              myPar2 = surface.LastUParameter();
            }
            else {
              myParIndex = 2;  // V periodic
              myPar1 = surface.FirstVParameter();
              myPar2 = surface.LastVParameter();
            }
          }
          // store seam shape indices, negative if shape encounters twice
          int edgeID = meshDS->ShapeToIndex( edge );
          mySeamShapeIds.insert( IsSeamShape( edgeID ) ? -edgeID : edgeID );
          for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) {
            int vertexID = meshDS->ShapeToIndex( v.Current() );
            mySeamShapeIds.insert( IsSeamShape( vertexID ) ? -vertexID : vertexID );
          }
        }

        // look for a degenerated edge
        if ( BRep_Tool::Degenerated( edge )) {
          myDegenShapeIds.insert( meshDS->ShapeToIndex( edge ));
          for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
            myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
        }
      }
    }
  }
}