/* A "safe" version of xosd_show that doesn't re-show the OSD if it's visible. */ void safe_show(xosd* osd) { if (!chkerror(xosd_is_onscreen(osd))) { chkerror(xosd_show(osd)); } }
/* A "safe" version of xosd_hide that doesn't re-hide the OSD if it's hidden. */ void safe_hide(xosd* osd) { if (chkerror(xosd_is_onscreen(osd))) { chkerror(xosd_hide(osd)); } }
static int testcase(Ndb_cluster_connection&cc, int flag) { ndbout << "--- case " << flag << " ---" << endl; sprintf(tab, "TB%02d", flag); alignAddr = ! (flag & 1); ndbout << (alignAddr ? "align addresses" : "mis-align addresses") << endl; alignSize = ! (flag & 2); ndbout << (alignSize ? "align data sizes" : "mis-align data sizes") << endl; useBuf = ! (flag & 4); ndbout << (useBuf ? "use our buffers" : "use ndbapi buffers") << endl; noRandom = ! (flag & 8); ndbout << (noRandom ? "simple sizes" : "randomize sizes") << endl; int smax = 0, stot = 0, i; if (xverbose) ndbout << "- define table " << tab << endl; for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; memset(&c, 0, sizeof(c)); sprintf(c.aAttrName, "C%d", i); if (i == 0) { c.aAttrType = UnSigned; c.aAttrSize = 32; c.aArraySize = 1; c.aTupleKey = TupleKey; c.nullable = false; } else { c.aAttrType = String; c.aAttrSize = 8; c.aArraySize = makeSize(i); if (smax < c.aArraySize) smax = c.aArraySize; stot += c.aArraySize; c.aTupleKey = NoKey; c.nullable = true; if (xverbose) ndbout << "-- column " << i << " size=" << c.aArraySize << endl; } c.buf = toAligned(c.data); c.bufsiz = sizeof(c.data) - (c.buf - c.data); } ndbout << "tab=" << tab << " cols=" << attrcnt << " size max=" << smax << " tot=" << stot << endl; if ((tcon = NdbSchemaCon::startSchemaTrans(ndb)) == 0) return ndberror("startSchemaTransaction"); if ((top = tcon->getNdbSchemaOp()) == 0) return ndberror("getNdbSchemaOp"); if (top->createTable(tab) < 0) return ndberror("createTable"); for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (top->createAttribute( c.aAttrName, c.aTupleKey, c.aAttrSize, c.aArraySize, c.aAttrType, MMBased, c.nullable ) < 0) return ndberror("createAttribute col=%d", i); } if (tcon->execute() < 0) { if (! (tcon->getNdbError().code == 721 && existok)) return ndberror("execute"); ndbout << "using " << tab << endl; } else { ndbout << "created " << tab << endl; } top = 0; tcon = 0; if (xverbose) ndbout << "- delete" << endl; int delcnt = 0; for (key = 0; key < opercnt; key++) { if ((con = ndb->startTransaction()) == 0) return ndberror("startTransaction key=%d", key); if ((op = con->getNdbOperation(tab)) == 0) return ndberror("getNdbOperation key=%d", key); if (op->deleteTuple() < 0) return ndberror("deleteTuple key=%d", key); for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) return ndberror("equal key=%d", key); } else { } } if (con->execute(Commit) < 0) { if (con->getNdbError().code != 626) return ndberror("execute key=%d", key); } else { delcnt++; } ndb->closeTransaction(con); } con = 0; op = 0; ndbout << "deleted " << delcnt << endl; if (xverbose) ndbout << "- insert" << endl; for (key = 0; key < opercnt; key++) { int off = makeOff(key); if ((con = ndb->startTransaction()) == 0) return ndberror("startTransaction key=%d", key); if ((op = con->getNdbOperation(tab)) == 0) return ndberror("getNdbOperation key=%d", key); if (op->insertTuple() < 0) return ndberror("insertTuple key=%d", key); for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) return ndberror("equal key=%d", key); } else { memset(c.buf, 'A', c.bufsiz); for (int j = 0; j < c.aArraySize; j++) c.buf[j + off] = byteVal(key, i, j); if (op->setValue(c.aAttrName, c.buf + off, c.aArraySize) < 0) return ndberror("setValue key=%d col=%d", key, i); } } if (con->execute(Commit) < 0) return ndberror("execute key=%d", key); ndb->closeTransaction(con); } con = 0; op = 0; ndbout << "inserted " << key << endl; if (xverbose) ndbout << "- select" << endl; for (key = 0; key < opercnt; key++) { int off = makeOff(key); if (xverbose) ndbout << "-- key " << key << " off=" << off << endl; if ((con = ndb->startTransaction()) == 0) return ndberror("startTransaction key=%d", key); if ((op = con->getNdbOperation(tab)) == 0) return ndberror("getNdbOperation key=%d", key); if (op->readTuple() < 0) return ndberror("readTuple key=%d", key); for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) return ndberror("equal key=%d", key); } else { if (xverbose) { char tmp[20]; if (useBuf) sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; } memset(c.buf, 'B', c.bufsiz); if (useBuf) { if (op->getValue(c.aAttrName, c.buf + off) < 0) return ndberror("getValue key=%d col=%d", key, i); } else { if ((c.aRa = op->getValue(c.aAttrName)) == 0) return ndberror("getValue key=%d col=%d", key, i); } } } if (con->execute(Commit) != 0) return ndberror("execute key=%d", key); for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { } else if (useBuf) { int j; for (j = 0; j < off; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); } } for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); } } } else { char* buf = c.aRa->aRef(); if (buf == 0) return ndberror("null aRef key=%d col%d", key, i); for (int j = 0; j < c.aArraySize; j++) { if (buf[j] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), buf[j]); } } } } ndb->closeTransaction(con); } con = 0; op = 0; ndbout << "selected " << key << endl; if (xverbose) ndbout << "- scan" << endl; char found[MaxOper]; int k; for (k = 0; k < opercnt; k++) found[k] = 0; for (key = 0; key < opercnt; key++) { int off = makeOff(key); if (xverbose) ndbout << "-- key " << key << " off=" << off << endl; int newkey = 0; if ((con = ndb->startTransaction()) == 0) return ndberror("startTransaction key=%d", key); if ((op = sop = con->getNdbScanOperation(tab)) == 0) return ndberror("getNdbOperation key=%d", key); if (sop->readTuples(1)) return ndberror("openScanRead key=%d", key); { col& c = ccol[0]; if (op->load_const_u32(1, key) < 0) return ndberror("load_const_u32"); if (op->read_attr(c.aAttrName, 2) < 0) return ndberror("read_attr"); if (op->branch_eq(1, 2, 0) < 0) return ndberror("branch_eq"); if (op->interpret_exit_nok() < 0) return ndberror("interpret_exit_nok"); if (op->def_label(0) < 0) return ndberror("def_label"); if (op->interpret_exit_ok() < 0) return ndberror("interpret_exit_ok"); } for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->getValue(c.aAttrName, (char*)&newkey) < 0) return ndberror("getValue key=%d col=%d", key, i); } else { if (xverbose) { char tmp[20]; if (useBuf) sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; } memset(c.buf, 'C', c.bufsiz); if (useBuf) { if (op->getValue(c.aAttrName, c.buf + off) < 0) return ndberror("getValue key=%d col=%d", key, i); } else { if ((c.aRa = op->getValue(c.aAttrName)) == 0) return ndberror("getValue key=%d col=%d", key, i); } } } if (con->execute(NoCommit) < 0) return ndberror("executeScan key=%d", key); int ret, cnt = 0; while ((ret = sop->nextResult()) == 0) { if (key != newkey) return ndberror("unexpected key=%d newkey=%d", key, newkey); for (i = 1; i < attrcnt; i++) { col& c = ccol[i]; if (useBuf) { int j; for (j = 0; j < off; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); } } for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); } } } else { char* buf = c.aRa->aRef(); if (buf == 0) return ndberror("null aRef key=%d col%d", key, i); for (int j = 0; j < c.aArraySize; j++) { if (buf[j] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), buf[j]); } } } } cnt++; } if (ret < 0) return ndberror("nextScanResult key=%d", key); if (cnt != 1) return ndberror("scan key=%d found %d", key, cnt); found[key] = 1; ndb->closeTransaction(con); } con = 0; op = 0; for (k = 0; k < opercnt; k++) if (! found[k]) return ndberror("key %d not found", k); ndbout << "scanned " << key << endl; ndbout << "done" << endl; return 0; }