bool check(const char *str,double _value){ node n,*result; int val; n.type = tdouble; n.value.d = _value; printf("Trying %s \n",str); result=parse(str); val=isEqual(&n,result); freeNode(result); return val; }
TEST(DictionarySerializationTest, IntegerAsStringKeys) { AmfDictionary d(true, false); d.insert(AmfInteger(3), AmfBool(false)); isEqual(v8 { 0x11, // AMF_DICTIONARY 0x03, // 1 element 0x00, // no weak keys 0x06, 0x03, 0x33, // AmfInteger 3 serialized as AmfString "3" 0x02 // AmfBool false }, d); d = AmfDictionary(true, false); d.insert(AmfInteger(-16384), AmfString("foo")); isEqual(v8 { 0x11, // AMF_DICTIONARY 0x03, // 1 element 0x00, // no weak keys 0x06, 0x0D, 0x2D, 0x31, 0x36, 0x33, 0x38, 0x34, 0x06, 0x07, 0x66, 0x6F, 0x6F }, d); }
static MimeTypeElement * isExist(MimeTypeElement **typelist, NPMIMEType type) { MimeTypeElement *ele; ele = *typelist; while (ele != NULL) { if (isEqual(ele->pinst->type, type)) return ele; ele = ele->next; } return NULL; }
TEST(DictionarySerializationTest, IntegerKeys) { AmfDictionary d(false, false); d.insert(AmfInteger(3), AmfBool(false)); isEqual(v8 { 0x11, // AMF_DICTIONARY 0x03, // 1 element 0x00, // no weak keys 0x04, 0x03, // AmfInteger 3 0x02 // AmfBool false }, d); d = AmfDictionary(false, false); d.insert(AmfInteger(-16384), AmfString("foo")); isEqual(v8 { 0x11, // AMF_DICTIONARY 0x03, // 1 element 0x00, // no weak keys 0x04, 0xFF, 0xFF, 0xC0, 0x00, 0x06, 0x07, 0x66, 0x6F, 0x6F }, d); }
TEST(DictionarySerializationTest, BooleanKeys) { AmfDictionary d(false, false); d.insert(AmfBool(true), AmfBool(false)); isEqual(v8 { 0x11, 0x03, // 1 element 0x00, // no weak keys 0x03, // AmfBool true 0x02 // AmfBool false }, d); d = AmfDictionary(false, true); d.insert(AmfBool(false), AmfBool(true)); isEqual(v8 { 0x11, 0x03, // 1 element 0x01, // weak keys 0x02, // AmfBool false 0x03 // AmfBool true }, d); }
int findTestID(struct prinfo* tmp,int size,char*test_name) { int i; // char test_name[17] = "est.processtest"; for(i=0;i<size;i++) { if(isEqual(tmp[i].comm,test_name) == 1) { return tmp[i].pid; } } return -1; }
TEST(DictionarySerializationTest, BooleanAsStringKeys) { AmfDictionary d(true, false); d.insert(AmfBool(true), AmfBool(false)); isEqual(v8 { 0x11, 0x03, // 1 element 0x00, // no weak keys 0x06, 0x09, 0x74, 0x72, 0x75, 0x65, // AmfString "true" 0x02 // AmfBool false }, d); d = AmfDictionary(true, true); d.insert(AmfBool(false), AmfBool(true)); isEqual(v8 { 0x11, 0x03, // 1 element 0x01, // weak keys 0x06, 0x0B, 0x66, 0x61, 0x6C, 0x73, 0x65, // AmfString "false" 0x03 // AmfBool true }, d); }
TEST(StringSerializationTest, Ascii) { isEqual(v8 { 0x06, 0x07, 0x62, 0x61, 0x72 }, "bar"); isEqual(v8 { 0x06, 0x0D, 0x62, 0x6F, 0x6F, 0x66, 0x61, 0x72 }, "boofar"); isEqual(v8 { 0x06, 0x07, 0x71, 0x75, 0x78 }, "qux"); isEqual(v8 { 0x06, 0x07, 0x71, 0x75, 0x7A }, "quz"); isEqual(v8 { 0x06, 0x09, 0x71, 0x75, 0x75, 0x78 }, "quux"); isEqual(v8 { 0x06, 0x07, 0x22, 0x27, 0x5C }, "\"'\\"); }
void decomp_affine(const Matrix<4,4,F32> & mat, AffineParts * parts) { GraphicGems::HMatrix ggMat; GraphicGems::AffineParts ggParts; for (S32 i=0; i<4; i++) { for (S32 j=0; j<4; j++) ggMat[i][j] = mat[i][j]; } GraphicGems::decomp_affine(ggMat,&ggParts); parts->rot = Quaternion(F32(ggParts.q.x),F32(ggParts.q.y),F32(ggParts.q.z),F32(ggParts.q.w)); parts->scale = Point3D(F32(ggParts.k.x),F32(ggParts.k.y),F32(ggParts.k.z)); parts->scaleRot = Quaternion(F32(ggParts.u.x),F32(ggParts.u.y),F32(ggParts.u.z),F32(ggParts.u.w)); parts->trans = Point3D(F32(ggParts.t.x),F32(ggParts.t.y),F32(ggParts.t.z)); parts->sign = F32(ggParts.f); #ifdef TEST_DTS_MATH // Test math (but only in the unscaled case if (isEqual(parts->scale.x(),1.0f,0.01f) && isEqual(parts->scale.y(),1.0f,0.01f) && isEqual(parts->scale.z(),1.0f,0.01f)) { Matrix<4,4,F32> mat2 = parts->rot.toMatrix(); Vector<F32,4> col; col[0] = parts->trans.x(); col[1] = parts->trans.y(); col[2] = parts->trans.z(); col[3] = 1; mat2.setCol(3,col); for (S32 i=0; i<4; i++) { for (S32 ii=0; ii<4; ii++) { if (!isEqual(mat[i][ii],mat2[i][ii],0.01f)) AppConfig::PrintDump(-1,"Doh!"); } } } #endif }
CollisionReport Seg2Seg(const Seg& a, const Seg& b) { CollisionReport report; glm::vec2 r = a.B - a.A; glm::vec2 s = b.B - b.A; glm::vec2 PQ = b.A - a.A; float rxs = cross2D(r, s); if (isEqual(rxs, 0.0f)) { // collinear or parallel float PQxr = cross2D (PQ, r); if (isEqual (PQxr, 0.0f, 1e-8f)) { // collinear float a0 = 0.0; float a1 = glm::dot (r,r); float b0 = glm::dot (PQ, r); float b1 = glm::dot (b.B - a.A, r); float am = std::min (a0, a1); float aM = std::max (a0, a1); float bm = std::min (b0, b1); float bM = std::max (b0, b1); if (bm >= aM || bM <= am) return report; report.collide = true; report.distance = 0.0f; } return report; } // if we get here then we need to compute t and u float t = cross2D(PQ, s) / rxs; float u = cross2D(PQ, r) / rxs; if (t >= 0.0f && t <=1.0f && u >= 0.0f && u <= 1.0f) { // intersection report.collide = true; report.distance = t * glm::length(r); } return report; }
TEST(ObjectSerializationTest, NonTraitCtor) { AmfObject obj; obj.addSealedProperty("sealedProp", AmfInteger(0x7b)); isEqual(v8 { 0x0a, // AMF_OBJECT 0x13, // U29O-traits, not dynamic, 1 sealed prop 0x01, // class-name "" // UTF-8-vr "sealedProp" 0x15, 0x73, 0x65, 0x61, 0x6c, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x70, // sealed property value // AmfInteger 0x7b 0x04, 0x7b // no dynamic members }, obj); obj = AmfObject("foo", true, false); obj.addSealedProperty("sealedProp", AmfInteger(0x7b)); obj.addDynamicProperty("dynamicProp", AmfString("dyn")); isEqual(v8 { 0x0a, // AMF_OBJECT 0x1b, // U29O-traits, dynamic, 1 sealed prop // class-name UTF-8-vr "foo" 0x07, 0x66, 0x6f, 0x6f, // UTF-8-vr "sealedProp" 0x15, 0x73, 0x65, 0x61, 0x6c, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x70, // sealed property value // AmfInteger 0x7b 0x04, 0x7b, // 1 dynamic member // UTF-8-vr "dynamicProp" 0x17, 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x50, 0x72, 0x6f, 0x70, // AmfString "dyn" 0x06, 0x07, 0x64, 0x79, 0x6e, // end of dynamic members 0x01 }, obj); }
bool isIsosceles(double s1, double s2, double s3) { if(isEqual(s1,s2) && !isEqual(s2,s3) && !isEqual(s1,s3)) { return true; } else if(isEqual(s1,s3) && !isEqual(s3,s2) && !isEqual(s1,s2)) { return true; } else if(isEqual(s2,s3) && !isEqual(s3,s1) && !isEqual(s2,s1)) { return true; } else { return false; } }
void deleteFolder(char folder[], int passes, int recursive) { // Handle top folder DIR* dir; struct dirent *ent; if ( (dir = opendir(folder)) != NULL) { while ( (ent = readdir(dir)) != NULL) { // Delete only the top level char * fullPath = malloc(PATH_MAX); sprintf(fullPath,"%s/%s",folder,ent->d_name); if (!recursive) { if (ent->d_type != DT_DIR) { deleteFile(fullPath,passes); } } else { if (!isEqual(ent->d_name,".") && !isEqual(ent->d_name,"..")) { if (ent->d_type == DT_DIR) { deleteFolder(fullPath,passes,recursive); } else { deleteFile(fullPath,passes); } } } free(fullPath); } closedir(dir); if (!keepFiles) { rmdir(folder); if (errno == ENOTEMPTY) { printf("\nWARNING: UNABLE TO DELETE FOLDER AS FILE(S) MIGHT STILL EXIST."); } } } }
/* * +----------------+ * | 3 | 2 | * +----------------+ * | -|- | # # | * | # # | -|- | * +----------------+ * * +---------------+-------+-------+-------+-------+-------+-------+ * | 6 | 7 | 4 | 5 | 9 | 0 | 8 | 1 | * +---------------+-------+-------+-------+-------+-------+-------+ * | # - | - # | # - | - # | # - | - # | - - | - - | * | - # | # - | # - | - # | - - | - - | - # | # - | * +---------------+-------+-------+-------+-------+-------+-------+ * * w - width of shape to match * h - width of shape to match * * hd - height delta - 1/4 th of height * * center_x - shape center - middle of max_x min_x * center_y - shape center - middle of max_y min_y * * tw - top width width 1/4 the from top * bw - bottom width width 1/4 the from bottom * */ int Shape::matchBox() { bool TOP_L = false; bool BOT_L = false; bool TOP_R = false; bool BOT_R = false; int w = max_x - min_x; int h = max_y - min_y; int hd = h / 4; int tw = widthAt(min_y + hd, 4); int tm = midpoint; if( ! isEqual(tw, w)) { //if top not full wide as shape if(tm > center_x ) TOP_R = true; //if top center on right of shape center else TOP_L = true; //if top center on left of shape center } int bw = widthAt(max_y - hd, 4); int bm = midpoint; if( ! isEqual(bw, w) ) { //if bottom not full wide as ahape if(bm > center_x ) BOT_R = true; //if bottom center on right of shape center else BOT_L = true; //if bottom center on left of shape center } d_debugMatchBox(w, tw, tm, bw, bm); if( TOP_L && BOT_R ) return 6; if( TOP_R && BOT_L ) return 7; if( TOP_L && BOT_L ) return 4; if( TOP_R && BOT_R ) return 5; if( BOT_R ) return 8; if( TOP_L ) return 9; if( TOP_R ) return 0; if( BOT_L ) return 1; return -1; }
void ArrayObject::uniqueKey() { for(S32 i=0; i<mArray.size(); i++) { for(S32 j=i+1; j<mArray.size(); j++) { if( isEqual( mArray[i].key, mArray[j].key ) ) { erase(j); j--; } } } }
/* input: [[1,2,3],[4,5,6],[7,8,9,],[10,11,12]] output:[[1,2,3],[4,5,6],[7,8,9,],[10,11,12]] */ void test3(){ unsigned int M = 1; unsigned int N = 2; FFT_Type* input = (FFT_Type*)malloc(sizeof(FFT_Type*)*M*N); FFT_Type* output = (FFT_Type*)malloc(sizeof(FFT_Type*)*M*N); assert(input); assert(output); for(int i = 0; i < M * N; i++){ input[i] = i; } FFT2(M, N, input, output); assert(isEqual(output[0], 1)); assert(isEqual(output[1], -1)); fprintf(stderr, "the third test passes\n"); free(input); free(output); }
TEST(DictionarySerializationTest, NumberAsStringKeys) { AmfDictionary d(true, true); d.insert(AmfDouble(-0.5), AmfInteger(3)); isEqual(v8 { 0x11, 0x03, // 1 element 0x01, // weak keys 0x06, 0x09, 0x2D, 0x30, 0x2E, 0x35, // AmfString "-0.5" 0x04, 0x03 // AmfInteger 3 }, d); d = AmfDictionary(true, false); d.insert(AmfDouble(1.2345678912345e+35), AmfArray()); isEqual(v8 { 0x11, 0x03, // 1 element 0x00, // no weak keys // AmfString "1.2345678912345e+35" 0x06, 0x27, 0x31, 0x2e, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x31, 0x32, 0x33, 0x34, 0x35, 0x65, 0x2b, 0x33, 0x35, 0x09, 0x01, 0x01 // empty AmfArray }, d); }
void add_without_dup(file_array_t fArray, char* name, int op_type){ int i; for(i = 0; i<fArray->size; i++){ if(isEqual(fArray->array[i].name,name)){ fArray->array[i].op_type = fArray->array[i].op_type | op_type; return; } } //not duplicated fArray->array[fArray->size].name = name; fArray->array[fArray->size].op_type = op_type; fArray->size++; }
boost::optional<uint64_t> BTree<K, Comp>::lookup(K key) { BufferFrame* leafFrame = traverseToLeaf(key, false); Node<K, Comp>* leaf = reinterpret_cast<Node<K, Comp>*>(leafFrame->getData()); uint64_t pos = leaf->findKeyPos(key, smaller); uint64_t tid = std::numeric_limits<uint64_t>::max(); bool found = false; if (pos < leaf->count && isEqual(key, leaf->keyValuePairs[pos].first, smaller)) { found = true; tid = leaf->keyValuePairs[pos].second; } bufferManager.unfixPage(*leafFrame, false); return boost::optional<uint64_t> { found, tid }; }
bool MatrixMxN<Scalar>::operator== (const MatrixMxN<Scalar> &mat2) const { unsigned int rows1 = (*this).rows(); unsigned int cols1 = (*this).cols(); unsigned int rows2 = mat2.rows(); unsigned int cols2 = mat2.cols(); if((rows1 != rows2)||(cols1 != cols2)) return false; for(unsigned int i = 0; i < rows1; ++i) for(unsigned int j = 0; j < cols1; ++j) if(isEqual((*this)(i,j),mat2(i,j)) == false) return false; return true; }
void DFA::parseLine(string line) { vector<string> x = split(line, '='); if(x.size() == 2) { if(isEqual(x[0], "Q")) { // cout << x[0] << " => " << x[1] << endl; getInts(x[1], Q); if(verbose) cout << "Q +>\n" << Q << endl; } else if(isEqual(x[0], "T")) { this->getTheTransitions(T, x[1], 0); if(verbose) cout << "T +>\n" << T << endl; } else if(isEqual(x[0], "F")) { getInts(x[1], F); if(verbose) cout << "F +>\n" << F << endl; } else if(isEqual(x[0], "q0")) { q0 = atoi( x[1].c_str() ); } } }
int test3(){ bool* GRID; bool* NGRID; int pass=1; GRID = new bool[N*N]; NGRID = new bool[N*N]; copyAtoB(BEACON_1,GRID); for (int g = 0; g<100;g++){ serial::getNextGeneration(GRID, NGRID,N,N); if (!isEqual(NGRID,BEACON_1)&&(g%2)){ pass = 0; } if(!isEqual(NGRID,BEACON_2)&&!(g%2)){ pass = 0; } std::swap(GRID, NGRID); } delete GRID; delete NGRID; return pass; }
int isPalindrome(char *str) { char temp[MAX_SIZE]; cleanStr(str); copyStr(str, temp); reverseStr(temp); if(isEqual(str, temp)){ return 1; } return 0; }
TEST(DictionarySerializationTest, NumberAsStringsDoesntAffectObjects) { SerializationContext ctx; AmfDictionary d(true); d.insert(AmfArray(), AmfDictionary(false)); d.insert(AmfArray(std::vector<AmfInteger> { 1 }), AmfObject("", true, false)); consistsOf(std::vector<v8> { { // header 0x11, 0x05, // 2 elements 0x00 // no weak keys }, { // [] = {} 0x09, 0x01, 0x01, // empty array 0x11, 0x01, 0x00 // empty array }, { // [1] = {} 0x09, 0x03, 0x01, 0x04, 0x01, // AmfArray [1] 0x0a, 0x0b, 0x01, 0x01 // empty dynamic anonymous object } }, d.serialize(ctx)); AmfObject obj("foo", true, false); obj.addDynamicProperty("prop", AmfString("val")); AmfVector<int> vec { { 1, 2, 3 }, false }; d = AmfDictionary(true); d.insert(obj, vec); isEqual({ 0x11, 0x03, // 1 element 0x00, // no weak keys // key 0x0a, // AMF_OBJECT 0x0b, // U29O-traits | dynamic, 0 sealed properties 0x07, 0x66, 0x6f, 0x6f, // class-name "foo" // dynamic-member 0x09, 0x70, 0x72, 0x6f, 0x70, // UTF-8-vr "prop" 0x06, 0x07, 0x76, 0x61, 0x6c, // AmfString "val" 0x01, // end of object (UTF-8-empty) // value 0x0d, 0x07, 0x00, // AmfVector<int> with 3 elements 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03 }, d); }
///////////////////////////////////////////////////// // défine a plane with given points // returns a vector which contains coefficient a,b,c,d of the plane if the plane exists // or an empty vector if the plane does not exist static std::vector<double> definePlane(std::vector < gml::Point3D > const &points) { int len=0; double a, b, c, norm; double xi, yi, zi, xj, yj, zj, xc, yc, zc; int i= 0; std::vector<double> result; int iNxt; a = b = c = xc = yc = zc = 0.0; do { iNxt = 0; xi = points[i][0]; yi = points[i][1]; zi = points[i][2]; iNxt= (i == (int)points.size()-1)?0:i+1; xj = points[iNxt][0]; yj = points[iNxt][1]; zj = points[iNxt][2]; a += ( yi - yj ) * ( zi + zj ); b += ( zi - zj ) * ( xi + xj ); c += ( xi - xj ) * ( yi + yj ); xc += xi; yc += yi; zc += zi; len++; i++; } while( i < (int)points.size() ); norm = sqrt( a * a + b * b + c * c ); double w = (-len); if(! isEqual(norm, 0) ) { result.push_back(a / norm); result.push_back(b / norm); result.push_back(c / norm); result.push_back((result[0] * xc + result[1] * yc + result[2] * zc) / w); return result; } return result; }
TEST(ArraySerializationTest, StrictIntArray) { AmfInteger v0(0); AmfInteger v1(1); AmfInteger v2(2); AmfInteger v3(3); std::vector<AmfInteger> dense({{ v0, v1, v2, v3 }}); AmfArray array(dense); isEqual(v8 { 0x09, 0x09, 0x01, 0x04, 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03 }, array); }
int main() { enum Enum { E1, E2, E3 } v1, v2; v1 = E1; v2 = E1; isEqual(v1, v2); }
/* * Entry point */ int main(int argc, char** argv) { bool testInstall = false; char* installPath = "/srv/PufferPanel"; char* installUser; char* distro = getDistro(); if (isEqual(distro, "ubuntu")) { installUser = "******"; } else if (isEqual(distro, "debian")) { installUser = "******"; } else if (isEqual(distro, "unknown")) { installUser = "******"; } else { installUser = "******"; } bool doLangOnly = false; bool doConfigOnly = false; /* * Process command line arguments */ int i = 1; while (i < argc) { if (isEqual(argv[i], "-u")) { if (i + 1 < argc - 1) { printUsage(argv[0]); return (EXIT_FAILURE); } else { i++; installUser = argv[i]; } } else if (isEqual(argv[i], "-t")) { testInstall = true; } else if (isEqual(argv[i], "-v")) { printf("PufferPanel Installer - Version C-%s (%s)\n", INSTALLERVERSION, PPVERSION); return (EXIT_SUCCESS); } else if (isEqual(argv[i], "-h")) { printUsage(argv[0]); return (EXIT_SUCCESS); } else { printUsage(argv[0]); return (EXIT_FAILURE); } i++; } startLogging(); int returnCode = innerMain(testInstall, installPath, installUser); closeLogging(); return returnCode; }
bool ExifWrapper::isUnsupportedFileType( const QString& extension ) { QStringList fileTypes; fileTypes << "txt"; fileTypes << "png"; fileTypes << "raw"; foreach(const QString& type, fileTypes) { if (isEqual(extension, type)) { return true; } } return false; }
void ArrayObject::crop( ArrayObject *obj ) { for( S32 i = 0; i < obj->count(); i++ ) { const String &tempkey = obj->getKeyFromIndex( i ); for( S32 j = 0; j < mArray.size(); j++ ) { if( isEqual( mArray[j].key, tempkey ) ) { mArray.erase( j ); j--; } } } }