| 600 | } |
| 601 | |
| 602 | void TestDUChain::testImportStructure() |
| 603 | { |
| 604 | Timer total; |
| 605 | qDebug() << "before: " << KDevelop::RecursiveImportRepository::repository()->statistics().print(); |
| 606 | |
| 607 | ///Maintains a naive import-structure along with a real top-context import structure, and allows comparing both. |
| 608 | int cycles = 5; |
| 609 | //int cycles = 100; |
| 610 | //srand(time(NULL)); |
| 611 | for (int t = 0; t < cycles; ++t) { |
| 612 | QList<TestContext*> allContexts; |
| 613 | //Create a random structure |
| 614 | int contextCount = 50; |
| 615 | int verifyOnceIn = contextCount /*((contextCount*contextCount)/20)+1*/; //Verify once in every chances(not in all cases, because else the import-structure isn't built on-demand!) |
| 616 | int clearOnceIn = contextCount; |
| 617 | for (int a = 0; a < contextCount; a++) |
| 618 | allContexts << new TestContext(); |
| 619 | |
| 620 | for (int c = 0; c < cycles; ++c) { |
| 621 | //qDebug() << "main-cycle" << t << "sub-cycle" << c; |
| 622 | //Add random imports and compare |
| 623 | for (int a = 0; a < contextCount; a++) { |
| 624 | //Import up to 5 random other contexts into each context |
| 625 | int importCount = rand() % 5; |
| 626 | //qDebug() << "cnt> " << importCount; |
| 627 | for (int i = 0; i < importCount; ++i) { |
| 628 | //int importNr = rand() % contextCount; |
| 629 | //qDebug() << "nmr > " << importNr; |
| 630 | //allContexts[a]->import(allContexts[importNr]); |
| 631 | allContexts[a]->import(allContexts[rand() % contextCount]); |
| 632 | } |
| 633 | |
| 634 | for (int b = 0; b < contextCount; b++) |
| 635 | if (rand() % verifyOnceIn == 0) |
| 636 | allContexts[b]->verify(allContexts); |
| 637 | } |
| 638 | |
| 639 | //Remove random imports and compare |
| 640 | for (int a = 0; a < contextCount; a++) { |
| 641 | //Import up to 5 random other contexts into each context |
| 642 | int removeCount = rand() % 3; |
| 643 | QSet<TestContext*> removeImports; |
| 644 | for (int i = 0; i < removeCount; ++i) |
| 645 | if (!allContexts[a]->imports.isEmpty()) |
| 646 | removeImports.insert(allContexts[a]->imports[rand() % allContexts[a]->imports.count()]); |
| 647 | |
| 648 | allContexts[a]->unImport(removeImports.values()); |
| 649 | |
| 650 | for (int b = 0; b < contextCount; b++) |
| 651 | if (rand() % verifyOnceIn == 0) |
| 652 | allContexts[b]->verify(allContexts); |
| 653 | } |
| 654 | |
| 655 | for (int a = 0; a < contextCount; a++) { |
| 656 | if (rand() % clearOnceIn == 0) { |
| 657 | allContexts[a]->clearImports(); |
| 658 | allContexts[a]->verify(allContexts); |
| 659 | } |