text:
'use strict';

const assert = require('assert');
const should = require('should');
const uuid = require('uuid/v1');
const _ = require('lodash');

const GeoPoint = require('loopback-datasource-juggler').GeoPoint;

const initialization = require("./init.js");
const exampleData = require("./exampleData.js");

describe('couchbase test cases', function() {
  this.timeout(10000);

  let db, countries, CountryModel, CountryModelWithId,
    StudentModel, UserModel, TeamModel, MerchantModel;

  before(function(done) {
    db = initialization.getDataSource();
    countries = exampleData.countries;
    CountryModel = db.define('CountryModel', {
      gdp: Number,
      countryCode: String,
      name: String,
      population: Number,
      updatedAt: Date
    }, {
      forceId: false
    });
    CountryModelWithId = db.define('CountryModelWithId', {
      id: {type: String, id: true},
      gdp: Number,
      countryCode: String,
      name: String,
      population: Number,
      updatedAt: Date
    });
    StudentModel = db.define('StudentModel', {
      name: {type: String, length: 255},
      age: {type: Number},
      parents: {type: Object}
    }, {
      forceId: false
    });
    UserModel = db.define('UserModel', {
      name: {type: String, length: 255},
      email: {type: String, length: 255},
      realm: {type: Boolean}
    }, {
      forceId: false
    });
    TeamModel = db.define('TeamModel', {
      name: {type: String, length: 255},
      numberOfPlayers: {type: Number},
      sport: {type: String},
      image: {type: Buffer},
      location: {type: GeoPoint}
    }, {
      forceId: true
    });
    MerchantModel = db.define('MerchantModel', {
      merchantId: {type: String, id: true},
      name: {type: String, length: 255},
      countryId: String,
      address: {type: [Object], required: false}
    });

    deleteAllModelInstances(done);
  });

  describe('create document', function() {
    function verifyCountryRows(err, m) {
      should.not.exists(err);
      should.exist(m && m.id);
      should.exist(m && m.gdp);
      should.exist(m && m.countryCode);
      should.exist(m && m.name);
      should.exist(m && m.population);
      should.exist(m && m.updatedAt);
      m.gdp.should.be.type('number');
      m.countryCode.should.be.type('string');
      m.name.should.be.type('string');
      m.population.should.be.type('number');
      m.updatedAt.should.be.type('object');
    }

    it('create a document and generate an id', function(done) {
      CountryModel.create(countries[0], function(err, res) {
        verifyCountryRows(err, res);
        done();
      });
    });

    it('create a document that has an id defined', function(done) {
      const id = uuid();

      let newCountry = _.omit(countries[0]);
      newCountry.id = id;
      CountryModelWithId.create(newCountry, function(err, res) {
        should.not.exists(err);
        assert.equal(res.id, id);
        verifyCountryRows(err, res);
        done();
      });
    });

    it('create a document that has an id defined but empty', function(done) {
      const id = uuid();

      let newCountry = _.omit(countries[0]);
      CountryModelWithId.create(newCountry, function(err, res) {
        should.not.exists(err);
        should.exist(res && res.id);
        verifyCountryRows(err, res);
        done();
      });
    });

    it('create a document that has a property named equal to a reserved word', function(done) {
      const id = uuid();

      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function(err, res) {
        should.not.exists(err);
        should.exist(res && res.id);
        should.exist(res && res.name);
        should.exist(res && res.email);
        should.exist(res && res.realm);
        done();
      });
    });
  });

  describe('find document', function() {
    beforeEach(function(done) {
      deleteAllModelInstances(done);
    });

    it('find all instances without filter', function(done) {
      CountryModelWithId.create(countries[0], function(err, country) {
        CountryModelWithId.create(countries[1], function(err, country) {
          StudentModel.create({name: 'Juan Almeida', age: 30}, function(err, person) {
            CountryModelWithId.find(function(err, response) {
              should.not.exist(err);
              response.length.should.be.equal(2);
              done();
            });
          });
        });
      });
    });

    // TODO: Improve assertions
    it('find one instance with limit and skip', function(done) {
      CountryModelWithId.create(countries[0], function(err, country) {
        CountryModelWithId.create(countries[1], function(err, country) {
          StudentModel.create({name: 'Juan Almeida', age: 30}, function(err, person) {
            StudentModel.find({limit: 1, offset: 0}, function(err, response) {
              should.not.exist(err);
              response.length.should.be.equal(1);

              CountryModelWithId.find({limit: 1, offset: 1}, function(err, response) {
                should.not.exist(err);
                response.length.should.be.equal(1);
                done();
              });
            });
          });
        });
      });
    });

    it('retrieve only one field', function(done) {
      CountryModelWithId.create(countries[0], function(err, country) {
        CountryModelWithId.create(countries[1], function(err, country) {
          StudentModel.create({name: 'Juan Almeida', age: 30}, function(err, person) {
            CountryModelWithId.find({fields: ['name', 'population']}, function(err, response) {
              should.not.exist(err);
              response.length.should.be.equal(2);
              should.exist(response[0].name);
              should.exist(response[0].population);
              should.not.exist(response[0].id);
              done();
            });
          });
        });
      });
    });

    it('should allow to find using equal', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: 'Ecuador'}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should allow to find using like', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {like: 'E%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should allow to find using ilike', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {ilike: 'e%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should allow to find using ilike case 2', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {ilike: 'E%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should allow to find using ilike case 3', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {ilike: ''}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should allow to find using ilike case 4', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {countryCode: {ilike: 'ECU'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',0);
          done();
        });
      });
    });

    it('should support like for no match', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {like: 'M%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',0);
          done();
        });
      });
    });

    it('should allow to find using nlike', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {nlike: 'E%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',0);
          done();
        });
      });
    });

    it('should support nlike for no match', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {name: {nlike: 'M%or'}}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should support "and" operator that is satisfied', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {and: [
          {name: 'Ecuador'},
          {countryCode: 'EC'}
        ]}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should support "and" operator that is not satisfied', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {and: [
          {name: 'Ecuador'},
          {countryCode: 'CO'}
        ]}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',0);
          done();
        });
      });
    });

    it('should support "or" operator that is satisfied', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {or: [
          {name: 'Ecuador'},
          {countryCode: 'CO'}
        ]}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should support "or" operator that is not satisfied', function(done) {
      CountryModel.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModel.find({where: {or: [
          {name: 'Ecuador1'},
          {countryCode: 'EC1'}
        ]}}, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',0);
          done();
        });
      });
    });

    it('should support select a field named as a reserved word', function(done) {
      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function(err, res) {
        should.not.exists(err);

        UserModel.findOne({
          fields: ['name', 'realm']
        }, function(err, user) {
          should.not.exists(err);
          user.should.have.property('name','Juan Almeida');
          user.should.have.property('realm',true);
          done();
        });
      });
    });

    it('should support find based on a field named as a reserved word', function(done) {
      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function(err, res) {
        should.not.exists(err);

        UserModel.find({
          where: {realm: true}
        }, function(err, response) {
          should.not.exists(err);
          response.should.have.property('length',1);
          done();
        });
      });
    });

    it('should support is missing operator', function(done) {
      const countries = [
        {name: 'Ecuador'},
        {name: 'Colombia', countryCode: 'CO'}
      ];
      CountryModel.create(countries, function(err, res) {
        should.not.exists(err);

        CountryModel.find({
          where: {countryCode: 'ismissing'}
        }, function(err, response) {
          should.not.exists(err);
          console.log(response)
          response.length.should.equal(1);
          response[0].name.should.equal('Ecuador');
          done();
        });
      });
    });

    describe('null vals in different operators', function() {
      let defaultCountry = _.omit(exampleData.countries[0]);

      it('should handle null in inq operator', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Ecuador';
        defaultCountry.countryCode = 'EC';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.find({where: {id: {inq: [null, id]}}}, function(err, response) {
            should.not.exist(err);
            response.length.should.equal(1);
            response[0].name.should.equal('Ecuador');
            response[0].id.should.equal(id);
            done();
          });
        });
      });

      it('should handle null in nin operator', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Peru';
        defaultCountry.countryCode = 'PE';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.find({where: {id: {nin: [null, uuid()]}}}, function(err, response) {
            should.not.exist(err);
            response.length.should.equal(1);
            response[0].name.should.equal('Peru');
            response[0].id.should.equal(id);
            done();
          });
        });
      });

      it('should handle null in neq operator', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Ecuador';
        defaultCountry.countryCode = 'EC';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.find({where: {id: {neq: null}}}, function(err, response) {
            should.not.exist(err);
            response.length.should.equal(1);
            response[0].name.should.equal('Ecuador');
            response[0].id.should.equal(id);
            done();
          });
        });
      });

      it('should handle null in neq operator', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.updatedAt = undefined;

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.find({where: {and: [
              {id: {nin: [null]}},
              {name: {nin: [null]}},
              {countryCode: {nin: [null]}}
            ]}}, function(err, response) {
            should.not.exist(err);
            response.length.should.equal(1);
            done();
          });
        });
      });

      it('should support where for count', function(done) {
        CountryModel.create({name: 'My Country', countryCode: 'MC'}, function(err, response) {
          CountryModel.count({and: [
            {name: 'My Country'},
            {countryCode: 'MC'},
          ]}, function(err, count) {
            should.not.exist(err);
            count.should.be.equal(1);
            CountryModel.count({and: [
              {name: 'My Country1'},
              {countryCode: 'MC'},
            ]}, function(err, count) {
              should.not.exist(err);
              count.should.be.equal(0);
              CountryModel.count(function(err, count) {
                should.not.exist(err);
                count.should.be.equal(1);
                done();
              });
            });
          });
        });
      });
    });

    describe('findById method', function() {
      let defaultCountry = _.omit(exampleData.countries[1]);

      it('should return one document', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Ecuador';
        defaultCountry.countryCode = 'EC';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exist(err);
            response.name.should.equal('Ecuador');
            response.id.should.equal(id);
            done();
          });
        });
      });
    });

    describe('exists method', function() {
      let defaultCountry = _.omit(exampleData.countries[1]);

      it('should return true because document exists', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Peru';
        defaultCountry.countryCode = 'PE';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.exists(id, function(err, response) {
            should.not.exist(err);
            response.should.be.true;
            done();
          });
        });
      });

      it('should return false because document does not exists', function(done) {
        let id = uuid();

        defaultCountry.id = id;
        defaultCountry.name = 'Peru';
        defaultCountry.countryCode = 'PE';

        CountryModelWithId.create(defaultCountry, function(err, response) {
          should.not.exist(err);
          response.id.should.equal(defaultCountry.id);

          CountryModelWithId.exists(uuid(), function(err, response) {
            should.not.exist(err);
            response.should.be.false;
            done();
          });
        });
      });
    });
  });

  describe('delete document', function() {
    beforeEach(function(done) {
      deleteAllModelInstances(done);
    });

    it('deleteAll model instances without filter', function(done) {
      CountryModelWithId.create(countries[0], function(err, country) {
        CountryModelWithId.create(countries[1], function(err, country) {
          StudentModel.create({name: 'Juan Almeida', age: 30}, function(err, person) {
            CountryModelWithId.destroyAll(function(err) {
              should.not.exist(err);

              StudentModel.count(function(err, studentsNumber) {
                should.not.exist(err);
                studentsNumber.should.be.equal(1);

                CountryModelWithId.count(function(err, countriesNumber) {
                  should.not.exist(err);
                  countriesNumber.should.be.equal(0);
                  done();
                })
              })
            });
          });
        });
      });
    });

    it('should support where for destroyAll', function(done) {
      CountryModelWithId.create({name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModelWithId.create({name: 'Peru', countryCode: 'PE'}, function(err, country) {
          CountryModelWithId.destroyAll({and: [
            {name: 'Ecuador'},
            {countryCode: 'EC'}
          ]}, function(err) {
            should.not.exist(err);
            CountryModelWithId.count(function(err, count) {
              should.not.exist(err);
              count.should.be.equal(1);
              done();
            });
          });
        });
      });
    });

    it('should support where for destroyAll with a reserved word', function(done) {
      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function(err, response) {
        should.not.exist(err);

        UserModel.destroyAll({
          realm: true
        }, function(err, response) {
          should.not.exist(err);

          UserModel.count(function(err, count) {
            should.not.exist(err);
            count.should.be.equal(0);
            done();
          });
        });
      });
    });

    it('should support destroyById', function(done) {
      const id1 = uuid();
      const id2 = uuid();

      CountryModelWithId.create({id: id1, name: 'Ecuador', countryCode: 'EC'}, function(err, country) {
        CountryModelWithId.create({id: id2, name: 'Peru', countryCode: 'PE'}, function(err, country) {
          CountryModelWithId.destroyById(id1, function(err) {
            should.not.exist(err);
            CountryModelWithId.count(function(err, count) {
              should.not.exist(err);
              count.should.be.equal(1);
              done();
            });
          });
        });
      });
    });
  });

  describe('update document', function() {
    let country, countryId;

    beforeEach(function(done) {
      deleteAllModelInstances(done);
    });

    it('updateAttributes of a document', function(done) {
      const id = uuid();

      CountryModelWithId.create(
        {id: id, name: 'Panama', countryCode: 'PA'},
        function(err, country) {
          should.not.exists(err);
          country.name.should.be.equal('Panama');
          country.countryCode.should.be.equal('PA');

          country.updateAttributes(
            {name: 'Ecuador', countryCode: 'EC'},
            function(err, response) {
              should.not.exists(err);
              response.name.should.be.equal('Ecuador');
              response.countryCode.should.be.equal('EC');

              CountryModelWithId.findById(id, function(err, response) {
                should.not.exists(err);
                response.name.should.be.equal('Ecuador');
                response.countryCode.should.be.equal('EC');
                done();
              });
          });
      });
    });

    it('updateAttributes of a document with a reserved word', function(done) {
      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function(err, user) {
        should.not.exists(err);

        user.updateAttributes({
          realm: false
        }, function(err, response) {
          should.not.exists(err);

          UserModel.findOne(function(err, user) {
            should.not.exists(err);

            user.name.should.be.equal('Juan Almeida');
            user.realm.should.be.false;
            done();
          });
        });
      });
    });

    it('updateAttribute of a document', function(done) {
      const id = uuid();

      CountryModelWithId.create(
        {id: id, name: 'Panama', countryCode: 'PA'},
        function(err, country) {
          should.not.exists(err);
          country.name.should.be.equal('Panama');
          country.countryCode.should.be.equal('PA');

          CountryModelWithId.findById(id, function(err, country) {
            should.not.exists(err);
            country.updateAttribute('name', 'Ecuador', function(err, response) {
              should.not.exists(err);
              response.id.should.be.equal(id);
              response.name.should.be.equal('Ecuador');
              response.countryCode.should.be.equal('PA');
              done();
            });
          });
        });
    });

    it('create a document using save', function(done) {
      const id = uuid();

      let newCountry = new CountryModelWithId({
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      });

      CountryModelWithId.findById(id, function(err, response) {
        should.not.exists(err);
        should.not.exist(response);

        newCountry.save(function(err, instance) {
          should.not.exists(err);
          instance.id.should.be.equal(id);
          instance.name.should.be.equal('Colombia');
          instance.countryCode.should.be.equal('CO');

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            done();
          });
        });
      });
    });

    it('create a document with a reserved word using save', function(done) {
      const id = uuid();

      let newUser = new UserModel({
        name: 'Jobsity',
        email: 'admin@jobsity.io',
        realm: true
      });

      newUser.save(function(err, instance) {
        should.not.exists(err);

        instance.name.should.be.equal('Jobsity');
        instance.email.should.be.equal('admin@jobsity.io');
        instance.realm.should.be.true;

        UserModel.findOne(function(err, response) {
          should.not.exists(err);

          response.realm.should.be.true;
          done();
        });
      });
    });

    it('update a document using save', function(done) {
      const id = uuid();

      CountryModelWithId.create({
        id: id,
        name: 'Argentina',
        countryCode: 'AR'
      }, function (err, response) {
        should.not.exists(err);

        CountryModelWithId.findOne({
          where: {id: id}
        }, function(err, country) {
          should.not.exists(err);

          country.countryCode = 'EC';
          country.save(function(err, response) {
            should.not.exists(err);

            CountryModelWithId.findById(id, function(err, response) {
              should.not.exists(err);

              response.id.should.be.equal(id);
              response.name.should.be.equal('Argentina');
              response.countryCode.should.be.equal('EC');
              done();
            })
          })
        })
      })
    });

    it('update a document with a reserved word using save', function(done) {
      const id = uuid();

      UserModel.create({
        name: 'Juan Almeida',
        email: 'admin@admin.com',
        realm: true
      }, function (err, response) {
        should.not.exists(err);

        UserModel.findOne(function(err, user) {
          should.not.exists(err);

          user.realm = false;
          user.save(function(err, response) {
            should.not.exists(err);

            UserModel.findOne(function(err, response) {
              should.not.exists(err);

              response.name.should.be.equal('Juan Almeida');
              response.realm.should.be.false;
              done();
            });
          });
        });
      });
    });

    it('create a document using updateOrCreate', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      CountryModelWithId.findById(id, function(err, response) {
        should.not.exists(err);
        should.not.exist(response);

        CountryModelWithId.updateOrCreate(newCountry, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            done();
          });
        });
      });
    });

    it('update a document using updateOrCreate', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      let updatedCountry = {
        id: id,
        name: 'Ecuador'
      };

      CountryModelWithId.create(newCountry, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.updateOrCreate(updatedCountry, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            response.name.should.be.equal('Ecuador');
            response.countryCode.should.be.equal('CO');
            done();
          });
        });
      });
    });

    it('create a document using replaceOrCreate', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      CountryModelWithId.findById(id, function(err, response) {
        should.not.exists(err);
        should.not.exist(response);

        CountryModelWithId.replaceOrCreate(newCountry, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            done();
          });
        });
      });
    });

    it('update a document using replaceOrCreate', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      let updatedCountry = {
        id: id,
        name: 'Ecuador'
      };

      CountryModelWithId.create(newCountry, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.replaceOrCreate(updatedCountry, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            response.name.should.be.equal('Ecuador');
            should.not.exists(response.countryCode);
            done();
          });
        });
      });
    });

    it('update a document using replaceById', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      let updatedCountry = {
        id: id,
        name: 'Ecuador'
      };

      CountryModelWithId.create(newCountry, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.replaceById(id, updatedCountry, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            response.name.should.be.equal('Ecuador');
            should.not.exists(response.countryCode);
            done();
          });
        });
      });
    });

    it('return affected documents number using updateAll', function(done) {
      const id1 = uuid();

      let newCountry1 = {
        id: id1,
        name: 'Colombia',
        countryCode: 'CO'
      };

      CountryModelWithId.create(newCountry1, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.updateAll({where: {id: id1}}, {name: 'My Country'}, function(err, response) {
          should.not.exists(err);
          response.count.should.be.equal(1);
          done();
        });
      });
    });

    it('update a document using upsertWithWhere', function(done) {
      const id = uuid();

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'EC'
      };

      CountryModelWithId.create(newCountry, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.upsertWithWhere({name: 'Colombia'}, {countryCode: 'CO'}, function(err, instance) {
          should.not.exists(err);

          CountryModelWithId.findById(id, function(err, response) {
            should.not.exists(err);
            response.id.should.be.equal(id);
            response.name.should.be.equal('Colombia');
            response.countryCode.should.be.equal('CO');
            done();
          });
        });
      });
    });
  });

  describe('operations with id', function() {
    beforeEach(function(done) {
      deleteAllModelInstances(done);
    });

    it('find by id a model with forceId true', function(done) {
      TeamModel.create({
        name: 'Real Madrid',
        numberOfPlayers: 22,
        sport: 'soccer'
      }, function(err, response) {
        should.not.exists(err);

        const id = response.id;
        TeamModel.findById(id, function(err, team) {
          should.not.exists(err);

          team.id.should.be.equal(id);
          done();
        });
      });
    });

    it('execute operations with a model with custom id', function(done) {
      const id = uuid();

      MerchantModel.create({
        merchantId: id,
        name: 'McDonalds',
        countryId: uuid()
      }, function(err, response) {
        should.not.exists(err);

        MerchantModel.findById(id, function(err, merchant) {
          should.not.exists(err);

          merchant.merchantId.should.be.equal(id);
          merchant.name.should.be.equal('McDonalds');

          MerchantModel.deleteById(id, function(err, response) {
            should.not.exists(err);

            MerchantModel.count(function(err, count) {
              should.not.exists(err);

              count.should.be.equal(0);
              done();
            });
          });
        });
      });
    });
  });

  describe('cases with special datatypes', function() {

    describe('fields with date', function() {
      beforeEach(function(done) {
        deleteAllModelInstances(done);
      });

      it('find by id a model with forceId true', function(done) {
        CountryModel.create({
          name: 'Ecuador',
          countryCode: 'EC',
          updatedAt: '1990-05-21'
        }, function(err, response) {
          should.not.exists(err);

          CountryModel.findOne(function(err, country) {
            should.not.exists(err);

            country.updatedAt.should.an.instanceOf(Date);
            done();
          });
        });
      });
    });

    describe('fields with date', function() {
      beforeEach(function(done) {
        deleteAllModelInstances(done);
      });

      it('date field should be an instance of Date Object', function(done) {
        CountryModel.create({
          name: 'Ecuador',
          countryCode: 'EC',
          updatedAt: '1990-05-21'
        }, function(err, response) {
          should.not.exists(err);

          CountryModel.findOne(function(err, country) {
            should.not.exists(err);

            country.updatedAt.should.an.instanceOf(Date);
            done();
          });
        });
      });
    });

    describe('tests with special datatypes', function() {
      beforeEach(function(done) {
        deleteAllModelInstances(done);
      });

      it('returns an array of results', function(done) {
        MerchantModel.create({
          name: 'Wallmart',
          countryId: uuid(),
          address: [
            {city: 'Quito', phone: '298221'},
            {city: 'Guayaquil', phone: '33253'}
          ]
        }, function(err, response) {
          should.not.exists(err);

          MerchantModel.create({
            name: 'OpinionShield',
            countryId: uuid(),
            address: [
              {city: 'Ambato', phone: '99857'},
              {city: 'Cuenca', phone: '22588442'}
            ]
          }, function(err, response) {
            should.not.exists(err);

            MerchantModel.find(function(err, response) {
              should.not.exists(err);

              response[0].address.should.an.instanceOf(Array);
              done();
            });
          });
        });
      });

      it('returns an array of results', function(done) {
        const address = ['Quito', 'Guayaquil']
        MerchantModel.create({
          name: 'Wallmart',
          countryId: uuid(),
          address: address
        }, function(err, response) {
          should.not.exists(err);

          MerchantModel.find(function(err, response) {
            should.not.exists(err);

            done();
          });
        });
      });

      it('does not stringify object type field', function(done) {
        StudentModel.create(
          {
            name: 'Juan Almeida',
            age: 30,
            parents: {
              mother: {
                name: 'Alexandra'
              },
              father: {
                name: 'Patricio'
              }
            }
          }, function(err, student) {
            should.not.exists(err);

            StudentModel.findOne(function(err, response) {
              should.not.exists(err);

              response.parents.mother.name.should.be.equal('Alexandra');
              done();
            });
          });
      });

      it('stores string and return string on object type field', function(done) {
        StudentModel.create(
          {
            name: 'Juan Almeida',
            age: 30,
            parents: 'myparents'
          }, function(err, student) {
            should.not.exists(err);

            StudentModel.findOne(function(err, response) {
              should.not.exists(err);

              response.parents.should.be.equal('myparents');
              done();
            });
          });
      });

      it('stores array and return array on object type field', function(done) {
        let testArray = [
          'item1',
          2,
          true,
          'apple'
        ];
        StudentModel.create(
          {
            name: 'Juan Almeida',
            age: 30,
            parents: testArray
          }, function(err, student) {
            should.not.exists(err);

            StudentModel.findOne(function(err, response) {
              should.not.exists(err);

              response.parents.should.be.deepEqual(testArray);
              done();
            });
          });
      });

      it('stores a buffer data type', function(done) {
        const buffer = new Buffer(42);

        TeamModel.create({
          name: 'Real Madrid',
          numberOfPlayers: 22,
          sport: 'soccer',
          image: buffer
        }, function(err, response) {
          should.not.exists(err);

          const id = response.id;
          TeamModel.findById(id, function(err, team) {
            should.not.exists(err);

            team.id.should.be.equal(id);
            team.image.should.an.instanceOf(Buffer);
            team.image.should.be.deepEqual(buffer);
            done();
          });
        });
      });

      it('should always return a buffer object', function(done) {
        TeamModel.create({
          name: 'Real Madrid',
          numberOfPlayers: 22,
          sport: 'soccer',
          image: 'MyImage.jpg'
        }, function(err, response) {
          should.not.exists(err);

          const id = response.id;
          TeamModel.findById(id, function(err, team) {
            should.not.exists(err);

            team.id.should.be.equal(id);
            team.image.should.an.instanceOf(Buffer);
            done();
          });
        });
      });

      it('should always return a geolocation object', function(done) {
        const point = new GeoPoint({
          lat: 31.230416,
          lng: 121.473701,
        });

        TeamModel.create({
          name: 'Real Madrid',
          numberOfPlayers: 22,
          sport: 'soccer',
          location: point
        }, function(err, response) {
          should.not.exists(err);

          const id = response.id;
          TeamModel.findById(id, function(err, team) {
            should.not.exists(err);

            point.lat.should.be.equal(team.location.lat);
            point.lng.should.be.equal(team.location.lng);
            done();
          });
        });
      });
    });
  });

  describe('tests for updateDocumentExpiration method', function() {
    beforeEach(function(done) {
      deleteAllModelInstances(done);
    });

    it('should change default document expiry time', function(done) {
      const id = uuid();
      const documentKey = 'CountryModelWithId::' + id;
      const expirationTime = 2;

      let newCountry = {
        id: id,
        name: 'Colombia',
        countryCode: 'CO'
      };

      CountryModelWithId.create(newCountry, function(err, response) {
        should.not.exists(err);

        CountryModelWithId.find(function(err, response) {
          should.not.exists(err);
          response.length.should.be.equal(1);

          CountryModelWithId.getDataSource().connector
          .updateDocumentExpiration(documentKey, expirationTime, {}, function (err, response) {
            should.not.exists(err);

            CountryModelWithId.find(function(err, response) {
              should.not.exists(err);
              response.length.should.be.equal(1);

              setTimeout(function() {
                CountryModelWithId.find(function(err, response) {
                  should.not.exists(err);
                  response.length.should.be.equal(0);
                  done();
                });
              }, 3000);
            });
          });
        });
      });
    });
  });

  function deleteAllModelInstances(callback) {
    const models = [
      CountryModel, CountryModelWithId,
      StudentModel, TeamModel,
      UserModel, MerchantModel
    ];
    return Promise.all(models.map((m) => {
      return new Promise(function(resolve,reject) {
        m.destroyAll(function(err) {
          if (err) {
            reject(err);
          } else {
            resolve();
          }
        });
      })
    }))
    .then(() => callback(null, true))
    .catch(err => callback(err));
  }

  after(function() {
    //return deleteAllModelInstances();
  })
});


text:
require 'dropbox_sdk'

#Contains the model of the documents of the use case.
class DocumentUseCase < ActiveRecord::Base
  attr_accessible :description, :name, :url_path, :use_case_id

  before_create :upload_file

  belongs_to :use_case

  validates :name, :presence => true
  validates :url_path, :presence => true

  # Uploads a file to a use case's directory of Dropbox
  def upload_file
	project = self.use_case.project

	file = url_path.read
    whole_name = url_path.original_filename
    final_name = self.name + ".v1.0" + File.extname(whole_name)
    file_path = project.name + "/UseCases/" + self.name + "/" + final_name
    dbsession = DropboxSession.deserialize(project.dropbox_token)
    client = DropboxClient.new(dbsession)
    response = client.put_file(file_path, file)
    link = client.shares(response["path"])
    self.url_path = link["url"]
  end

end

redpajama_set_name: RedPajamaGithub


text:
<legend class="admin__form-field-legend">

</legend>


text:
package com.thinkgem.jeesite.modules.cms.web.gongjin;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.servlet.ValidateCodeServlet;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.entity.*;
import com.thinkgem.jeesite.modules.cms.service.*;
import com.thinkgem.jeesite.modules.cms.utils.CmsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 网站Controller
 * @author Roger
 * @version 2017-10-01
 */
@Controller
@RequestMapping(value = "${frontPath}")
public class GongjinController extends BaseController{

	@Autowired
	private ArticleService articleService;
	@Autowired
	private ArticleDataService articleDataService;
	@Autowired
	private LinkService linkService;
	@Autowired
	private CommentService commentService;
	@Autowired
	private CategoryService categoryService;
	@Autowired
	private SiteService siteService;

	/**
	 * 网站首页
	 */
	@RequestMapping
	public String index(Model model) {
		Site site = CmsUtils.getSite(Site.defaultSiteId());
		model.addAttribute("site", site);
		model.addAttribute("isIndex", true);
		return "modules/cms/front/themes/gongjin/index";
	}

    /**
	 * 内容列表
	 */
	@RequestMapping(value = "article-{categoryId}")
	public String list(@PathVariable String categoryId, @RequestParam(required=false, defaultValue="1") Integer pageNo,
			@RequestParam(required=false, defaultValue="15") Integer pageSize, Model model) {
		Category category = categoryService.get(categoryId);
		if (category==null){
			Site site = CmsUtils.getSite(Site.defaultSiteId());
			model.addAttribute("site", site);
			return "error/404";
		}
		Site site = siteService.get(category.getSite().getId());
		model.addAttribute("site", site);
		// 2:简介类栏目,栏目第一条内容
		if("2".equals(category.getShowModes()) && "article".equals(category.getModule())){
			// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
			List<Category> categoryList = Lists.newArrayList();
			if (category.getParent().getId().equals("1")){
				categoryList.add(category);
			}else{
				categoryList = categoryService.findByParentId(category.getParent().getId(), category.getSite().getId());
			}
			model.addAttribute("category", category);
			model.addAttribute("categoryList", categoryList);
			// 获取文章内容
			Page<Article> page = new Page<Article>(1, 1, -1);
			Article article = new Article(category);
			page = articleService.findPage(page, article, false);
			if (page.getList().size()>0){
				article = page.getList().get(0);
				article.setArticleData(articleDataService.get(article.getId()));
				articleService.updateHitsAddOne(article.getId());
			}
			model.addAttribute("article", article);
            CmsUtils.addViewConfigAttribute(model, category);
            CmsUtils.addViewConfigAttribute(model, article.getViewConfig());
		}else{
			List<Category> categoryList = categoryService.findByParentId(category.getId(), category.getSite().getId());
			// 展现方式为1 、无子栏目或公共模型,显示栏目内容列表
			if("1".equals(category.getShowModes())||categoryList.size()==0){
				// 有子栏目并展现方式为1,则获取第一个子栏目;无子栏目,则获取同级分类列表。
				if(categoryList.size()>0){
					category = categoryList.get(0);
				}else{
					// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
					if (category.getParent().getId().equals("1")){
						categoryList.add(category);
					}else{
						categoryList = categoryService.findByParentId(category.getParent().getId(), category.getSite().getId());
					}
				}
				model.addAttribute("category", category);
				model.addAttribute("categoryList", categoryList);
				// 获取内容列表
				if ("article".equals(category.getModule())){
					Page<Article> page = new Page<Article>(pageNo, pageSize);
					//System.out.println(page.getPageNo());
					page = articleService.findPage(page, new Article(category), false);
					model.addAttribute("page", page);
					// 如果第一个子栏目为简介类栏目,则获取该栏目第一篇文章
					if ("2".equals(category.getShowModes())){
						Article article = new Article(category);
						if (page.getList().size()>0){
							article = page.getList().get(0);
							article.setArticleData(articleDataService.get(article.getId()));
							articleService.updateHitsAddOne(article.getId());
						}
						model.addAttribute("article", article);
			            CmsUtils.addViewConfigAttribute(model, category);
			            CmsUtils.addViewConfigAttribute(model, article.getViewConfig());
                    }
				}else if ("link".equals(category.getModule())){
					Page<Link> page = new Page<Link>(1, -1);
					page = linkService.findPage(page, new Link(category), false);
					model.addAttribute("page", page);
				}
				String view = "/frontList";
				if (StringUtils.isNotBlank(category.getCustomListView())){
					view = "/"+category.getCustomListView();
				}
	            CmsUtils.addViewConfigAttribute(model, category);
                site =siteService.get(category.getSite().getId());
            }
			// 有子栏目:显示子栏目列表
			else{
				model.addAttribute("category", category);
				model.addAttribute("categoryList", categoryList);
				String view = "/frontListCategory";
				if (StringUtils.isNotBlank(category.getCustomListView())){
					view = "/"+category.getCustomListView();
				}
	            CmsUtils.addViewConfigAttribute(model, category);
            }
		}

        return "modules/cms/front/themes/gongjin/article";
    }

}


text:
$(document).ready(function () {
	isOnPlaylist = false;
    function colorPickContent() {
        $('#mainContent').load('colorPick.html');
    }

    setTimeout(colorPickContent, 20000);
});


text:
require File.dirname(__FILE__) + '/../../spec_helper'

describe Admin::RecommendProductsController do
  fixtures :admin_users , :recommend_products, :products, :product_styles
  before(:each) do
    session[:admin_user] = admin_users(:admin10)
    @controller.class.skip_before_filter @controller.class.before_filter
    @controller.class.skip_after_filter @controller.class.after_filter
    @controller.class.before_filter :master_shop_check
  end

  #Delete these examples and add some real ones
  it "should use Admin::RecommendProductController" do
    controller.should be_an_instance_of(Admin::RecommendProductsController)
  end

  describe "GET 'index'" do
    it "初期表示の場合" do
      get 'index'
      response.should be_success
      assigns[:recommend_products].should == RecommendProduct.find(:all, :order => "position")
    end

    it "マスターショップ以外はアクセスできない" do
      session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
      get 'index'
      response.should redirect_to(:controller => "home", :action => "index")
    end
  end

  describe "POST 'update'" do
    it "データを更新する場合" do
      recommend_product = {:description => "オススメ商品です"}
      get 'update', :id=>1, :product_id=>1, :recommend_product => recommend_product
      RecommendProduct.find_by_id(1).description.should == recommend_product[:description]
      response.should redirect_to(:action=>"index")
    end
  end

  describe "GET 'destroy'" do
    it "should be successful" do
      #初期データの確認
      RecommendProduct.find(2).description.should == recommend_products(:test3).description
      RecommendProduct.find(2).product_id.should == recommend_products(:test3).product_id

      get 'destroy', :id=>2
      RecommendProduct.find_by_id(2).should be_nil
      flash[:notice].should == "削除しました"
      response.should redirect_to(:action=>"index")
    end

  end

  describe "GET 'update'" do
    it "データの更新に成功した場合" do
      recommend_product = {:product_id=>3, :description=>"データを更新しました"}
      get 'update', :id=>1, :recommend_product => recommend_product
      record = RecommendProduct.find(1)
      record.product_id.should == 3
      flash[:notice] = "保存しました"
      response.should redirect_to(:action=>"index")
    end

    it "データの更新に成功した場合(登録されていなかったところに登録)" do
      recommend_product = {:product_id=>3, :description=>"データを更新しました"}
      get 'update', :id=>3, :recommend_product => recommend_product
      record = RecommendProduct.find(3)
      record.product_id.should == 3
      record.description.should == "データを更新しました"
      flash[:notice] = "保存しました"
      response.should redirect_to(:action=>"index")
    end

    it "データの更新に失敗した場合" do
      recommend_product = {:product_id=>3, :description=> "a" * 1000}
      get 'update', :id=>6, :recommend_product => recommend_product
      RecommendProduct.find_by_id(6).description.should_not == "a" * 1000
      response.should render_template("admin/recommend_products/edit.html.erb")
    end
  end

  describe "GET 'product_search'" do
    it "検索画面が表示される" do
      get 'product_search', :id => "1"
      assigns[:products].should be_nil
      response.should be_success
    end

    it "商品が検索できる(商品名のみで検索)" do
      condition = {:keyword => "can", :searched => "true"}
      get 'product_search', :id => '1', :condition => condition
      assigns[:products].should_not be_nil
      response.should render_template("admin/recommend_products/product_search.html.erb")
    end

    it "商品が検索できる(カテゴリーのみで検索)" do
      condition = {:category_id => '1', :searched => "true"}
      get 'product_search', :id => '1', :condition => condition
      assigns[:products].should_not be_nil
      response.should render_template("admin/recommend_products/product_search.html.erb")
    end

    it "商品が検索できる(商品名とカテゴリーで検索)" do
      condition = {:keyword => "商品", :category_id => '1', :searched => "true"}
      get 'product_search', :id=>'1', :condition => condition
      assigns[:products].should_not be_nil
      response.should render_template("admin/recommend_products/product_search.html.erb")
    end

    it "商品が検索できる(条件なしで検索)" do
      condition = {:searched => "true"}
      get 'product_search', :id=>'1', :condition => condition
      assigns[:products].should_not be_nil
      response.should render_template("admin/recommend_products/product_search.html.erb")
    end

    it "商品が検索できる(1件もひっかからない)" do
      condition = {:keyword => "test", :category_id => '1', :searched => "true"}
      get 'product_search', :id=>'1', :condition => condition
      assigns[:products].should == []
      response.should render_template("admin/recommend_products/product_search.html.erb")
    end
  end

end


text:
package jetbrains.android.client;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class YouTrackPreference extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.youtrack_prefrences);
    }
}


text:
namespace android.app.backup
{
	[global::MonoJavaBridge.JavaClass()]
	public partial class FileBackupHelper : android.app.backup.FileBackupHelperBase, BackupHelper
	{
		internal new static global::MonoJavaBridge.JniGlobalHandle staticClass;
		static FileBackupHelper()
		{
			InitJNI();
		}
		protected FileBackupHelper(global::MonoJavaBridge.JNIEnv @__env) : base(@__env)
		{
		}
		internal static global::MonoJavaBridge.MethodId _performBackup944;
		public virtual void performBackup(android.os.ParcelFileDescriptor arg0, android.app.backup.BackupDataOutput arg1, android.os.ParcelFileDescriptor arg2)
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			if (!IsClrObject)
				@__env.CallVoidMethod(this.JvmHandle, global::android.app.backup.FileBackupHelper._performBackup944, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2));
			else
				@__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.app.backup.FileBackupHelper.staticClass, global::android.app.backup.FileBackupHelper._performBackup944, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2));
		}
		internal static global::MonoJavaBridge.MethodId _restoreEntity945;
		public virtual void restoreEntity(android.app.backup.BackupDataInputStream arg0)
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			if (!IsClrObject)
				@__env.CallVoidMethod(this.JvmHandle, global::android.app.backup.FileBackupHelper._restoreEntity945, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
			else
				@__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.app.backup.FileBackupHelper.staticClass, global::android.app.backup.FileBackupHelper._restoreEntity945, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
		}
		internal static global::MonoJavaBridge.MethodId _FileBackupHelper946;
		public FileBackupHelper(android.content.Context arg0, java.lang.String[] arg1)  : base(global::MonoJavaBridge.JNIEnv.ThreadEnv)
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject(android.app.backup.FileBackupHelper.staticClass, global::android.app.backup.FileBackupHelper._FileBackupHelper946, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1));
			Init(@__env, handle);
		}
		private static void InitJNI()
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			global::android.app.backup.FileBackupHelper.staticClass = @__env.NewGlobalRef(@__env.FindClass("android/app/backup/FileBackupHelper"));
			global::android.app.backup.FileBackupHelper._performBackup944 = @__env.GetMethodIDNoThrow(global::android.app.backup.FileBackupHelper.staticClass, "performBackup", "(Landroid/os/ParcelFileDescriptor;Landroid/app/backup/BackupDataOutput;Landroid/os/ParcelFileDescriptor;)V");
			global::android.app.backup.FileBackupHelper._restoreEntity945 = @__env.GetMethodIDNoThrow(global::android.app.backup.FileBackupHelper.staticClass, "restoreEntity", "(Landroid/app/backup/BackupDataInputStream;)V");
			global::android.app.backup.FileBackupHelper._FileBackupHelper946 = @__env.GetMethodIDNoThrow(global::android.app.backup.FileBackupHelper.staticClass, "<init>", "(Landroid/content/Context;[Ljava/lang/String;)V");
		}
	}
}


text:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32F3xx_LL_FMC_H
#define STM32F3xx_LL_FMC_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal_def.h"

/** @addtogroup STM32F3xx_HAL_Driver
  * @{
  */

/** @addtogroup FMC_LL
  * @{
  */

/** @addtogroup FMC_LL_Private_Macros
  * @{
  */
#if defined(FMC_BANK1)

#define IS_FMC_NORSRAM_BANK(__BANK__) (((__BANK__) == FMC_NORSRAM_BANK1) || \
                                       ((__BANK__) == FMC_NORSRAM_BANK2) || \
                                       ((__BANK__) == FMC_NORSRAM_BANK3) || \
                                       ((__BANK__) == FMC_NORSRAM_BANK4))
#define IS_FMC_MUX(__MUX__) (((__MUX__) == FMC_DATA_ADDRESS_MUX_DISABLE) || \
                             ((__MUX__) == FMC_DATA_ADDRESS_MUX_ENABLE))
#define IS_FMC_MEMORY(__MEMORY__) (((__MEMORY__) == FMC_MEMORY_TYPE_SRAM) || \
                                   ((__MEMORY__) == FMC_MEMORY_TYPE_PSRAM)|| \
                                   ((__MEMORY__) == FMC_MEMORY_TYPE_NOR))
#define IS_FMC_NORSRAM_MEMORY_WIDTH(__WIDTH__) (((__WIDTH__) == FMC_NORSRAM_MEM_BUS_WIDTH_8)  || \
                                                ((__WIDTH__) == FMC_NORSRAM_MEM_BUS_WIDTH_16) || \
                                                ((__WIDTH__) == FMC_NORSRAM_MEM_BUS_WIDTH_32))
#define IS_FMC_ACCESS_MODE(__MODE__) (((__MODE__) == FMC_ACCESS_MODE_A) || \
                                      ((__MODE__) == FMC_ACCESS_MODE_B) || \
                                      ((__MODE__) == FMC_ACCESS_MODE_C) || \
                                      ((__MODE__) == FMC_ACCESS_MODE_D))
#define IS_FMC_BURSTMODE(__STATE__) (((__STATE__) == FMC_BURST_ACCESS_MODE_DISABLE) || \
                                     ((__STATE__) == FMC_BURST_ACCESS_MODE_ENABLE))
#define IS_FMC_WAIT_POLARITY(__POLARITY__) (((__POLARITY__) == FMC_WAIT_SIGNAL_POLARITY_LOW) || \
                                            ((__POLARITY__) == FMC_WAIT_SIGNAL_POLARITY_HIGH))
#define IS_FMC_WRAP_MODE(__MODE__) (((__MODE__) == FMC_WRAP_MODE_DISABLE) || \
                                             ((__MODE__) == FMC_WRAP_MODE_ENABLE))
#define IS_FMC_WAIT_SIGNAL_ACTIVE(__ACTIVE__) (((__ACTIVE__) == FMC_WAIT_TIMING_BEFORE_WS) || \
                                               ((__ACTIVE__) == FMC_WAIT_TIMING_DURING_WS))
#define IS_FMC_WRITE_OPERATION(__OPERATION__) (((__OPERATION__) == FMC_WRITE_OPERATION_DISABLE) || \
                                               ((__OPERATION__) == FMC_WRITE_OPERATION_ENABLE))
#define IS_FMC_WAITE_SIGNAL(__SIGNAL__) (((__SIGNAL__) == FMC_WAIT_SIGNAL_DISABLE) || \
                                         ((__SIGNAL__) == FMC_WAIT_SIGNAL_ENABLE))
#define IS_FMC_EXTENDED_MODE(__MODE__) (((__MODE__) == FMC_EXTENDED_MODE_DISABLE) || \
                                        ((__MODE__) == FMC_EXTENDED_MODE_ENABLE))
#define IS_FMC_ASYNWAIT(__STATE__) (((__STATE__) == FMC_ASYNCHRONOUS_WAIT_DISABLE) || \
                                    ((__STATE__) == FMC_ASYNCHRONOUS_WAIT_ENABLE))
#define IS_FMC_DATA_LATENCY(__LATENCY__) (((__LATENCY__) > 1U) && ((__LATENCY__) <= 17U))
#define IS_FMC_WRITE_BURST(__BURST__) (((__BURST__) == FMC_WRITE_BURST_DISABLE) || \
                                       ((__BURST__) == FMC_WRITE_BURST_ENABLE))
#define IS_FMC_CONTINOUS_CLOCK(__CCLOCK__) (((__CCLOCK__) == FMC_CONTINUOUS_CLOCK_SYNC_ONLY) || \
                                            ((__CCLOCK__) == FMC_CONTINUOUS_CLOCK_SYNC_ASYNC))
#define IS_FMC_ADDRESS_SETUP_TIME(__TIME__) ((__TIME__) <= 15U)
#define IS_FMC_ADDRESS_HOLD_TIME(__TIME__) (((__TIME__) > 0U) && ((__TIME__) <= 15U))
#define IS_FMC_DATASETUP_TIME(__TIME__) (((__TIME__) > 0U) && ((__TIME__) <= 255U))
#define IS_FMC_DATAHOLD_DURATION(__DATAHOLD__) ((__DATAHOLD__) <= 3U)
#define IS_FMC_TURNAROUND_TIME(__TIME__) ((__TIME__) <= 15U)
#define IS_FMC_CLK_DIV(__DIV__) (((__DIV__) > 1U) && ((__DIV__) <= 16U))
#define IS_FMC_NORSRAM_DEVICE(__INSTANCE__) ((__INSTANCE__) == FMC_NORSRAM_DEVICE)
#define IS_FMC_NORSRAM_EXTENDED_DEVICE(__INSTANCE__) ((__INSTANCE__) == FMC_NORSRAM_EXTENDED_DEVICE)

#endif /* FMC_BANK1 */
#if defined(FMC_BANK3)

#define IS_FMC_NAND_BANK(__BANK__) ((__BANK__) == FMC_NAND_BANK3)
#define IS_FMC_WAIT_FEATURE(__FEATURE__) (((__FEATURE__) == FMC_NAND_PCC_WAIT_FEATURE_DISABLE) || \
                                                   ((__FEATURE__) == FMC_NAND_PCC_WAIT_FEATURE_ENABLE))
#define IS_FMC_NAND_MEMORY_WIDTH(__WIDTH__) (((__WIDTH__) == FMC_NAND_PCC_MEM_BUS_WIDTH_8) || \
                                                      ((__WIDTH__) == FMC_NAND_PCC_MEM_BUS_WIDTH_16))
#define IS_FMC_ECC_STATE(__STATE__) (((__STATE__) == FMC_NAND_ECC_DISABLE) || \
                                     ((__STATE__) == FMC_NAND_ECC_ENABLE))

#define IS_FMC_ECCPAGE_SIZE(__SIZE__) (((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_256BYTE)  || \
                                       ((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_512BYTE)  || \
                                       ((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_1024BYTE) || \
                                       ((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_2048BYTE) || \
                                       ((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_4096BYTE) || \
                                       ((__SIZE__) == FMC_NAND_ECC_PAGE_SIZE_8192BYTE))
#define IS_FMC_TCLR_TIME(__TIME__) ((__TIME__) <= 255U)
#define IS_FMC_TAR_TIME(__TIME__) ((__TIME__) <= 255U)
#define IS_FMC_SETUP_TIME(__TIME__) ((__TIME__) <= 254U)
#define IS_FMC_WAIT_TIME(__TIME__) ((__TIME__) <= 254U)
#define IS_FMC_HOLD_TIME(__TIME__) ((__TIME__) <= 254U)
#define IS_FMC_HIZ_TIME(__TIME__) ((__TIME__) <= 254U)
#define IS_FMC_NAND_DEVICE(__INSTANCE__) ((__INSTANCE__) == FMC_NAND_DEVICE)

#endif /* FMC_BANK3 */
#if defined(FMC_BANK4)
#define IS_FMC_PCCARD_DEVICE(__INSTANCE__) ((__INSTANCE__) == FMC_PCCARD_DEVICE)

#endif /* FMC_BANK4 */

/**
  * @}
  */

/* Exported typedef ----------------------------------------------------------*/

/** @defgroup FMC_LL_Exported_typedef FMC Low Layer Exported Types
  * @{
  */

#if defined(FMC_BANK1)
#define FMC_NORSRAM_TypeDef            FMC_Bank1_TypeDef
#define FMC_NORSRAM_EXTENDED_TypeDef   FMC_Bank1E_TypeDef
#endif /* FMC_BANK1 */
#if defined(FMC_BANK3)
#define FMC_NAND_TypeDef               FMC_Bank2_3_TypeDef
#endif /* FMC_BANK3 */
#if defined(FMC_BANK4)
#define FMC_PCCARD_TypeDef             FMC_Bank4_TypeDef
#endif /* FMC_BANK4 */

#if defined(FMC_BANK1)
#define FMC_NORSRAM_DEVICE             FMC_Bank1
#define FMC_NORSRAM_EXTENDED_DEVICE    FMC_Bank1E
#endif /* FMC_BANK1 */
#if defined(FMC_BANK3)
#define FMC_NAND_DEVICE                FMC_Bank2_3
#endif /* FMC_BANK3 */
#if defined(FMC_BANK4)
#define FMC_PCCARD_DEVICE              FMC_Bank4
#endif /* FMC_BANK4 */

#if defined(FMC_BANK1)
/**
  * @brief  FMC NORSRAM Configuration Structure definition
  */
typedef struct
{
  uint32_t NSBank;                       /*!< Specifies the NORSRAM memory device that will be used.
                                              This parameter can be a value of @ref FMC_NORSRAM_Bank                  */

  uint32_t DataAddressMux;               /*!< Specifies whether the address and data values are
                                              multiplexed on the data bus or not.
                                              This parameter can be a value of @ref FMC_Data_Address_Bus_Multiplexing */

  uint32_t MemoryType;                   /*!< Specifies the type of external memory attached to
                                              the corresponding memory device.
                                              This parameter can be a value of @ref FMC_Memory_Type                   */

  uint32_t MemoryDataWidth;              /*!< Specifies the external memory device width.
                                              This parameter can be a value of @ref FMC_NORSRAM_Data_Width            */

  uint32_t BurstAccessMode;              /*!< Enables or disables the burst access mode for Flash memory,
                                              valid only with synchronous burst Flash memories.
                                              This parameter can be a value of @ref FMC_Burst_Access_Mode             */

  uint32_t WaitSignalPolarity;           /*!< Specifies the wait signal polarity, valid only when accessing
                                              the Flash memory in burst mode.
                                              This parameter can be a value of @ref FMC_Wait_Signal_Polarity          */

  uint32_t WrapMode;                     /*!< Enables or disables the Wrapped burst access mode for Flash
                                              memory, valid only when accessing Flash memories in burst mode.
                                              This parameter can be a value of @ref FMC_Wrap_Mode                     */

  uint32_t WaitSignalActive;             /*!< Specifies if the wait signal is asserted by the memory one
                                              clock cycle before the wait state or during the wait state,
                                              valid only when accessing memories in burst mode.
                                              This parameter can be a value of @ref FMC_Wait_Timing                   */

  uint32_t WriteOperation;               /*!< Enables or disables the write operation in the selected device by the FMC.
                                              This parameter can be a value of @ref FMC_Write_Operation               */

  uint32_t WaitSignal;                   /*!< Enables or disables the wait state insertion via wait
                                              signal, valid for Flash memory access in burst mode.
                                              This parameter can be a value of @ref FMC_Wait_Signal                   */

  uint32_t ExtendedMode;                 /*!< Enables or disables the extended mode.
                                              This parameter can be a value of @ref FMC_Extended_Mode                 */

  uint32_t AsynchronousWait;             /*!< Enables or disables wait signal during asynchronous transfers,
                                              valid only with asynchronous Flash memories.
                                              This parameter can be a value of @ref FMC_AsynchronousWait              */

  uint32_t WriteBurst;                   /*!< Enables or disables the write burst operation.
                                              This parameter can be a value of @ref FMC_Write_Burst                   */

  uint32_t ContinuousClock;              /*!< Enables or disables the FMC clock output to external memory devices.
                                              This parameter is only enabled through the FMC_BCR1 register,
                                              and don't care through FMC_BCR2..4 registers.
                                              This parameter can be a value of @ref FMC_Continous_Clock               */
} FMC_NORSRAM_InitTypeDef;

/**
  * @brief  FMC NORSRAM Timing parameters structure definition
  */
typedef struct
{
  uint32_t AddressSetupTime;             /*!< Defines the number of HCLK cycles to configure
                                              the duration of the address setup time.
                                              This parameter can be a value between Min_Data = 0 and Max_Data = 15.
                                              @note This parameter is not used with synchronous NOR Flash memories.   */

  uint32_t AddressHoldTime;              /*!< Defines the number of HCLK cycles to configure
                                              the duration of the address hold time.
                                              This parameter can be a value between Min_Data = 1 and Max_Data = 15.
                                              @note This parameter is not used with synchronous NOR Flash memories.   */

  uint32_t DataSetupTime;                /*!< Defines the number of HCLK cycles to configure
                                              the duration of the data setup time.
                                              This parameter can be a value between Min_Data = 1 and Max_Data = 255.
                                              @note This parameter is used for SRAMs, ROMs and asynchronous multiplexed
                                              NOR Flash memories.                                                     */

  uint32_t BusTurnAroundDuration;        /*!< Defines the number of HCLK cycles to configure
                                              the duration of the bus turnaround.
                                              This parameter can be a value between Min_Data = 0 and Max_Data = 15.
                                              @note This parameter is only used for multiplexed NOR Flash memories.   */

  uint32_t CLKDivision;                  /*!< Defines the period of CLK clock output signal, expressed in number of
                                              HCLK cycles. This parameter can be a value between Min_Data = 2 and
                                              Max_Data = 16.
                                              @note This parameter is not used for asynchronous NOR Flash, SRAM or ROM
                                              accesses.                                                               */

  uint32_t DataLatency;                  /*!< Defines the number of memory clock cycles to issue
                                              to the memory before getting the first data.
                                              The parameter value depends on the memory type as shown below:
                                              - It must be set to 0 in case of a CRAM
                                              - It is don't care in asynchronous NOR, SRAM or ROM accesses
                                              - It may assume a value between Min_Data = 2 and Max_Data = 17
                                                in NOR Flash memories with synchronous burst mode enable              */

  uint32_t AccessMode;                   /*!< Specifies the asynchronous access mode.
                                              This parameter can be a value of @ref FMC_Access_Mode                   */
} FMC_NORSRAM_TimingTypeDef;
#endif /* FMC_BANK1 */

#if defined(FMC_BANK3)
/**
  * @brief  FMC NAND Configuration Structure definition
  */
typedef struct
{
  uint32_t NandBank;               /*!< Specifies the NAND memory device that will be used.
                                        This parameter can be a value of @ref FMC_NAND_Bank                  */

  uint32_t Waitfeature;            /*!< Enables or disables the Wait feature for the NAND Memory device.
                                        This parameter can be any value of @ref FMC_Wait_feature             */

  uint32_t MemoryDataWidth;        /*!< Specifies the external memory device width.
                                        This parameter can be any value of @ref FMC_NAND_Data_Width          */

  uint32_t EccComputation;         /*!< Enables or disables the ECC computation.
                                        This parameter can be any value of @ref FMC_ECC                      */

  uint32_t ECCPageSize;            /*!< Defines the page size for the extended ECC.
                                        This parameter can be any value of @ref FMC_ECC_Page_Size            */

  uint32_t TCLRSetupTime;          /*!< Defines the number of HCLK cycles to configure the
                                        delay between CLE low and RE low.
                                        This parameter can be a value between Min_Data = 0 and Max_Data = 255  */

  uint32_t TARSetupTime;           /*!< Defines the number of HCLK cycles to configure the
                                        delay between ALE low and RE low.
                                        This parameter can be a number between Min_Data = 0 and Max_Data = 255 */
} FMC_NAND_InitTypeDef;
#endif

#if defined(FMC_BANK3) || defined(FMC_BANK4)
/**
  * @brief  FMC NAND Timing parameters structure definition
  */
typedef struct
{
  uint32_t SetupTime;            /*!< Defines the number of HCLK cycles to setup address before
                                      the command assertion for NAND-Flash read or write access
                                      to common/Attribute or I/O memory space (depending on
                                      the memory space timing to be configured).
                                      This parameter can be a value between Min_Data = 0 and Max_Data = 254    */

  uint32_t WaitSetupTime;        /*!< Defines the minimum number of HCLK cycles to assert the
                                      command for NAND-Flash read or write access to
                                      common/Attribute or I/O memory space (depending on the
                                      memory space timing to be configured).
                                      This parameter can be a number between Min_Data = 0 and Max_Data = 254   */

  uint32_t HoldSetupTime;        /*!< Defines the number of HCLK clock cycles to hold address
                                      (and data for write access) after the command de-assertion
                                      for NAND-Flash read or write access to common/Attribute
                                      or I/O memory space (depending on the memory space timing
                                      to be configured).
                                      This parameter can be a number between Min_Data = 0 and Max_Data = 254   */

  uint32_t HiZSetupTime;         /*!< Defines the number of HCLK clock cycles during which the
                                      data bus is kept in HiZ after the start of a NAND-Flash
                                      write access to common/Attribute or I/O memory space (depending
                                      on the memory space timing to be configured).
                                      This parameter can be a number between Min_Data = 0 and Max_Data = 254   */
} FMC_NAND_PCC_TimingTypeDef;
#endif /* FMC_BANK3 */

#if defined(FMC_BANK4)
/**
  * @brief FMC PCCARD Configuration Structure definition
  */
typedef struct
{
  uint32_t Waitfeature;            /*!< Enables or disables the Wait feature for the PCCARD Memory device.
                                        This parameter can be any value of @ref FMC_Wait_feature      */

  uint32_t TCLRSetupTime;          /*!< Defines the number of HCLK cycles to configure the
                                        delay between CLE low and RE low.
                                        This parameter can be a value between Min_Data = 0 and Max_Data = 255  */

  uint32_t TARSetupTime;           /*!< Defines the number of HCLK cycles to configure the
                                        delay between ALE low and RE low.
                                        This parameter can be a number between Min_Data = 0 and Max_Data = 255 */
}FMC_PCCARD_InitTypeDef;
#endif

/**
  * @}
  */

/* Exported constants --------------------------------------------------------*/
/** @addtogroup FMC_LL_Exported_Constants FMC Low Layer Exported Constants
  * @{
  */
#if defined(FMC_BANK1)

/** @defgroup FMC_LL_NOR_SRAM_Controller FMC NOR/SRAM Controller
  * @{
  */

/** @defgroup FMC_NORSRAM_Bank FMC NOR/SRAM Bank
  * @{
  */
#define FMC_NORSRAM_BANK1                       (0x00000000U)
#define FMC_NORSRAM_BANK2                       (0x00000002U)
#define FMC_NORSRAM_BANK3                       (0x00000004U)
#define FMC_NORSRAM_BANK4                       (0x00000006U)
/**
  * @}
  */

/** @defgroup FMC_Data_Address_Bus_Multiplexing FMC Data Address Bus Multiplexing
  * @{
  */
#define FMC_DATA_ADDRESS_MUX_DISABLE            (0x00000000U)
#define FMC_DATA_ADDRESS_MUX_ENABLE             (0x00000002U)
/**
  * @}
  */

/** @defgroup FMC_Memory_Type FMC Memory Type
  * @{
  */
#define FMC_MEMORY_TYPE_SRAM                    (0x00000000U)
#define FMC_MEMORY_TYPE_PSRAM                   (0x00000004U)
#define FMC_MEMORY_TYPE_NOR                     (0x00000008U)
/**
  * @}
  */

/** @defgroup FMC_NORSRAM_Data_Width FMC NORSRAM Data Width
  * @{
  */
#define FMC_NORSRAM_MEM_BUS_WIDTH_8             (0x00000000U)
#define FMC_NORSRAM_MEM_BUS_WIDTH_16            (0x00000010U)
#define FMC_NORSRAM_MEM_BUS_WIDTH_32            (0x00000020U)
/**
  * @}
  */

/** @defgroup FMC_NORSRAM_Flash_Access FMC NOR/SRAM Flash Access
  * @{
  */
#define FMC_NORSRAM_FLASH_ACCESS_ENABLE         (0x00000040U)
#define FMC_NORSRAM_FLASH_ACCESS_DISABLE        (0x00000000U)
/**
  * @}
  */

/** @defgroup FMC_Burst_Access_Mode FMC Burst Access Mode
  * @{
  */
#define FMC_BURST_ACCESS_MODE_DISABLE           (0x00000000U)
#define FMC_BURST_ACCESS_MODE_ENABLE            (0x00000100U)
/**
  * @}
  */

/** @defgroup FMC_Wait_Signal_Polarity FMC Wait Signal Polarity
  * @{
  */
#define FMC_WAIT_SIGNAL_POLARITY_LOW            (0x00000000U)
#define FMC_WAIT_SIGNAL_POLARITY_HIGH           (0x00000200U)
/**
  * @}
  */

/** @defgroup FMC_Wrap_Mode FMC Wrap Mode
  * @{
  */
#define FMC_WRAP_MODE_DISABLE                   (0x00000000U)
#define FMC_WRAP_MODE_ENABLE                    (0x00000400U)
/**
  * @}
  */

/** @defgroup FMC_Wait_Timing FMC Wait Timing
  * @{
  */
#define FMC_WAIT_TIMING_BEFORE_WS               (0x00000000U)
#define FMC_WAIT_TIMING_DURING_WS               (0x00000800U)
/**
  * @}
  */

/** @defgroup FMC_Write_Operation FMC Write Operation
  * @{
  */
#define FMC_WRITE_OPERATION_DISABLE             (0x00000000U)
#define FMC_WRITE_OPERATION_ENABLE              (0x00001000U)
/**
  * @}
  */

/** @defgroup FMC_Wait_Signal FMC Wait Signal
  * @{
  */
#define FMC_WAIT_SIGNAL_DISABLE                 (0x00000000U)
#define FMC_WAIT_SIGNAL_ENABLE                  (0x00002000U)
/**
  * @}
  */

/** @defgroup FMC_Extended_Mode FMC Extended Mode
  * @{
  */
#define FMC_EXTENDED_MODE_DISABLE               (0x00000000U)
#define FMC_EXTENDED_MODE_ENABLE                (0x00004000U)
/**
  * @}
  */

/** @defgroup FMC_AsynchronousWait FMC Asynchronous Wait
  * @{
  */
#define FMC_ASYNCHRONOUS_WAIT_DISABLE           (0x00000000U)
#define FMC_ASYNCHRONOUS_WAIT_ENABLE            (0x00008000U)
/**
  * @}
  */

/** @defgroup FMC_Write_Burst FMC Write Burst
  * @{
  */
#define FMC_WRITE_BURST_DISABLE                 (0x00000000U)
#define FMC_WRITE_BURST_ENABLE                  (0x00080000U)
/**
  * @}
  */

/** @defgroup FMC_Continous_Clock FMC Continuous Clock
  * @{
  */
#define FMC_CONTINUOUS_CLOCK_SYNC_ONLY          (0x00000000U)
#define FMC_CONTINUOUS_CLOCK_SYNC_ASYNC         (0x00100000U)
/**
  * @}
  */

/** @defgroup FMC_Access_Mode FMC Access Mode
  * @{
  */
#define FMC_ACCESS_MODE_A                       (0x00000000U)
#define FMC_ACCESS_MODE_B                       (0x10000000U)
#define FMC_ACCESS_MODE_C                       (0x20000000U)
#define FMC_ACCESS_MODE_D                       (0x30000000U)
/**
  * @}
  */

/**
  * @}
  */
#endif /* FMC_BANK1 */

#if defined(FMC_BANK3) || defined(FMC_BANK4)

/** @defgroup FMC_LL_NAND_Controller FMC NAND Controller
  * @{
  */
/** @defgroup FMC_NAND_Bank FMC NAND Bank
  * @{
  */
#define FMC_NAND_BANK2                          (0x00000010U)
#define FMC_NAND_BANK3                          (0x00000100U)
/**
  * @}
  */

/** @defgroup FMC_Wait_feature FMC Wait feature
  * @{
  */
#define FMC_NAND_PCC_WAIT_FEATURE_DISABLE       (0x00000000U)
#define FMC_NAND_PCC_WAIT_FEATURE_ENABLE        (0x00000002U)
/**
  * @}
  */

/** @defgroup FMC_PCR_Memory_Type FMC PCR Memory Type
  * @{
  */
#if defined(FMC_BANK4)
#define FMC_PCR_MEMORY_TYPE_PCCARD              (0x00000000U)
#endif
#define FMC_PCR_MEMORY_TYPE_NAND                (0x00000008U)
/**
  * @}
  */

/** @defgroup FMC_NAND_Data_Width FMC NAND Data Width
  * @{
  */
#define FMC_NAND_PCC_MEM_BUS_WIDTH_8            (0x00000000U)
#define FMC_NAND_PCC_MEM_BUS_WIDTH_16           (0x00000010U)
/**
  * @}
  */

/** @defgroup FMC_ECC FMC ECC
  * @{
  */
#define FMC_NAND_ECC_DISABLE                    (0x00000000U)
#define FMC_NAND_ECC_ENABLE                     (0x00000040U)
/**
  * @}
  */

/** @defgroup FMC_ECC_Page_Size FMC ECC Page Size
  * @{
  */
#define FMC_NAND_ECC_PAGE_SIZE_256BYTE          (0x00000000U)
#define FMC_NAND_ECC_PAGE_SIZE_512BYTE          (0x00020000U)
#define FMC_NAND_ECC_PAGE_SIZE_1024BYTE         (0x00040000U)
#define FMC_NAND_ECC_PAGE_SIZE_2048BYTE         (0x00060000U)
#define FMC_NAND_ECC_PAGE_SIZE_4096BYTE         (0x00080000U)
#define FMC_NAND_ECC_PAGE_SIZE_8192BYTE         (0x000A0000U)
/**
  * @}
  */

/**
  * @}
  */
#endif /* FMC_BANK3 */

/** @defgroup FMC_LL_Interrupt_definition FMC Low Layer Interrupt definition
  * @{
  */
#if defined(FMC_BANK3) || defined(FMC_BANK4)
#define FMC_IT_RISING_EDGE                      (0x00000008U)
#define FMC_IT_LEVEL                            (0x00000010U)
#define FMC_IT_FALLING_EDGE                     (0x00000020U)
#endif /* FMC_BANK3 */
/**
  * @}
  */

/** @defgroup FMC_LL_Flag_definition FMC Low Layer Flag definition
  * @{
  */
#if defined(FMC_BANK3) || defined(FMC_BANK4)
#define FMC_FLAG_RISING_EDGE                    (0x00000001U)
#define FMC_FLAG_LEVEL                          (0x00000002U)
#define FMC_FLAG_FALLING_EDGE                   (0x00000004U)
#define FMC_FLAG_FEMPT                          (0x00000040U)
#endif /* FMC_BANK3 */
/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/* Private macro -------------------------------------------------------------*/
/** @defgroup FMC_LL_Private_Macros FMC_LL  Private Macros
  * @{
  */
#if defined(FMC_BANK1)
/** @defgroup FMC_LL_NOR_Macros FMC NOR/SRAM Macros
  * @brief macros to handle NOR device enable/disable and read/write operations
  * @{
  */

/**
  * @brief  Enable the NORSRAM device access.
  * @param  __INSTANCE__ FMC_NORSRAM Instance
  * @param  __BANK__ FMC_NORSRAM Bank
  * @retval None
  */
#define __FMC_NORSRAM_ENABLE(__INSTANCE__, __BANK__)  ((__INSTANCE__)->BTCR[(__BANK__)]\
                                                       |= FMC_BCRx_MBKEN)

/**
  * @brief  Disable the NORSRAM device access.
  * @param  __INSTANCE__ FMC_NORSRAM Instance
  * @param  __BANK__ FMC_NORSRAM Bank
  * @retval None
  */
#define __FMC_NORSRAM_DISABLE(__INSTANCE__, __BANK__) ((__INSTANCE__)->BTCR[(__BANK__)]\
                                                       &= ~FMC_BCRx_MBKEN)

/**
  * @}
  */
#endif /* FMC_BANK1 */

#if defined(FMC_BANK3)
/** @defgroup FMC_LL_NAND_Macros FMC NAND Macros
  *  @brief macros to handle NAND device enable/disable
  *  @{
  */

/**
  * @brief  Enable the NAND device access.
  * @param  __INSTANCE__ FMC_NAND Instance
  * @param  __BANK__     FMC_NAND Bank
  * @retval None
  */
#define __FMC_NAND_ENABLE(__INSTANCE__, __BANK__)  (((__BANK__) == FMC_NAND_BANK2)? ((__INSTANCE__)->PCR2 |= FMC_PCRx_PBKEN): \
                                                             ((__INSTANCE__)->PCR3 |= FMC_PCRx_PBKEN))

/**
  * @brief  Disable the NAND device access.
  * @param  __INSTANCE__ FMC_NAND Instance
  * @param  __BANK__     FMC_NAND Bank
  * @retval None
  */
#define __FMC_NAND_DISABLE(__INSTANCE__, __BANK__) (((__BANK__) == FMC_NAND_BANK2)? CLEAR_BIT((__INSTANCE__)->PCR2, FMC_PCRx_PBKEN): \
                                                             CLEAR_BIT((__INSTANCE__)->PCR3, FMC_PCRx_PBKEN))

/**
  * @}
  */
#endif

#if defined(FMC_BANK4)
/** @defgroup FMC_LL_PCCARD_Macros FMC PCCARD Macros
  *  @brief macros to handle PCCARD read/write operations
  *  @{
  */
/**
  * @brief  Enable the PCCARD device access.
  * @param  __INSTANCE__ FMC_PCCARD Instance
  * @retval None
  */
#define __FMC_PCCARD_ENABLE(__INSTANCE__)  ((__INSTANCE__)->PCR4 |= FMC_PCR4_PBKEN)

/**
  * @brief  Disable the PCCARD device access.
  * @param  __INSTANCE__ FMC_PCCARD Instance
  * @retval None
  */
#define __FMC_PCCARD_DISABLE(__INSTANCE__) ((__INSTANCE__)->PCR4 &= ~FMC_PCR4_PBKEN)
/**
  * @}
  */

#endif
#if defined(FMC_BANK3)
/** @defgroup FMC_LL_NAND_Interrupt FMC NAND Interrupt
  * @brief macros to handle NAND interrupts
  * @{
  */

/**
  * @brief  Enable the NAND device interrupt.
  * @param  __INSTANCE__  FMC_NAND instance
  * @param  __BANK__     FMC_NAND Bank
  * @param  __INTERRUPT__ FMC_NAND interrupt
  *         This parameter can be any combination of the following values:
  *            @arg FMC_IT_RISING_EDGE: Interrupt rising edge.
  *            @arg FMC_IT_LEVEL: Interrupt level.
  *            @arg FMC_IT_FALLING_EDGE: Interrupt falling edge.
  * @retval None
  */
#define __FMC_NAND_ENABLE_IT(__INSTANCE__, __BANK__, __INTERRUPT__)  (((__BANK__) == FMC_NAND_BANK2)? ((__INSTANCE__)->SR2 |= (__INTERRUPT__)): \
                                                                               ((__INSTANCE__)->SR3 |= (__INTERRUPT__)))

/**
  * @brief  Disable the NAND device interrupt.
  * @param  __INSTANCE__  FMC_NAND Instance
  * @param  __BANK__     FMC_NAND Bank
  * @param  __INTERRUPT__ FMC_NAND interrupt
  *         This parameter can be any combination of the following values:
  *            @arg FMC_IT_RISING_EDGE: Interrupt rising edge.
  *            @arg FMC_IT_LEVEL: Interrupt level.
  *            @arg FMC_IT_FALLING_EDGE: Interrupt falling edge.
  * @retval None
  */
#define __FMC_NAND_DISABLE_IT(__INSTANCE__, __BANK__, __INTERRUPT__)  (((__BANK__) == FMC_NAND_BANK2)? ((__INSTANCE__)->SR2 &= ~(__INTERRUPT__)): \
                                                                                ((__INSTANCE__)->SR3 &= ~(__INTERRUPT__)))

/**
  * @brief  Get flag status of the NAND device.
  * @param  __INSTANCE__ FMC_NAND Instance
  * @param  __BANK__     FMC_NAND Bank
  * @param  __FLAG__     FMC_NAND flag
  *         This parameter can be any combination of the following values:
  *            @arg FMC_FLAG_RISING_EDGE: Interrupt rising edge flag.
  *            @arg FMC_FLAG_LEVEL: Interrupt level edge flag.
  *            @arg FMC_FLAG_FALLING_EDGE: Interrupt falling edge flag.
  *            @arg FMC_FLAG_FEMPT: FIFO empty flag.
  * @retval The state of FLAG (SET or RESET).
  */
#define __FMC_NAND_GET_FLAG(__INSTANCE__, __BANK__, __FLAG__)  (((__BANK__) == FMC_NAND_BANK2)? (((__INSTANCE__)->SR2 &(__FLAG__)) == (__FLAG__)): \
                                                                         (((__INSTANCE__)->SR3 &(__FLAG__)) == (__FLAG__)))

/**
  * @brief  Clear flag status of the NAND device.
  * @param  __INSTANCE__ FMC_NAND Instance
  * @param  __BANK__     FMC_NAND Bank
  * @param  __FLAG__     FMC_NAND flag
  *         This parameter can be any combination of the following values:
  *            @arg FMC_FLAG_RISING_EDGE: Interrupt rising edge flag.
  *            @arg FMC_FLAG_LEVEL: Interrupt level edge flag.
  *            @arg FMC_FLAG_FALLING_EDGE: Interrupt falling edge flag.
  *            @arg FMC_FLAG_FEMPT: FIFO empty flag.
  * @retval None
  */
#define __FMC_NAND_CLEAR_FLAG(__INSTANCE__, __BANK__, __FLAG__)  (((__BANK__) == FMC_NAND_BANK2)? ((__INSTANCE__)->SR2 &= ~(__FLAG__)): \
                                                                           ((__INSTANCE__)->SR3 &= ~(__FLAG__)))

/**
  * @}
  */
#endif /* FMC_BANK3 */

#if defined(FMC_BANK4)
/** @defgroup FMC_LL_PCCARD_Interrupt FMC PCCARD Interrupt
  * @brief macros to handle PCCARD interrupts
  * @{
  */

/**
  * @brief  Enable the PCCARD device interrupt.
  * @param  __INSTANCE__ FMC_PCCARD instance
  * @param  __INTERRUPT__ FMC_PCCARD interrupt
  *         This parameter can be any combination of the following values:
  *            @arg FMC_IT_RISING_EDGE: Interrupt rising edge.
  *            @arg FMC_IT_LEVEL: Interrupt level.
  *            @arg FMC_IT_FALLING_EDGE: Interrupt falling edge.
  * @retval None
  */
#define __FMC_PCCARD_ENABLE_IT(__INSTANCE__, __INTERRUPT__)  ((__INSTANCE__)->SR4 |= (__INTERRUPT__))

/**
  * @brief  Disable the PCCARD device interrupt.
  * @param  __INSTANCE__ FMC_PCCARD instance
  * @param  __INTERRUPT__ FMC_PCCARD interrupt
  *         This parameter can be any combination of the following values:
  *            @arg FMC_IT_RISING_EDGE: Interrupt rising edge.
  *            @arg FMC_IT_LEVEL: Interrupt level.
  *            @arg FMC_IT_FALLING_EDGE: Interrupt falling edge.
  * @retval None
  */
#define __FMC_PCCARD_DISABLE_IT(__INSTANCE__, __INTERRUPT__)  ((__INSTANCE__)->SR4 &= ~(__INTERRUPT__))

/**
  * @brief  Get flag status of the PCCARD device.
  * @param  __INSTANCE__ FMC_PCCARD instance
  * @param  __FLAG__ FMC_PCCARD flag
  *         This parameter can be any combination of the following values:
  *            @arg  FMC_FLAG_RISING_EDGE: Interrupt rising edge flag.
  *            @arg  FMC_FLAG_LEVEL: Interrupt level edge flag.
  *            @arg  FMC_FLAG_FALLING_EDGE: Interrupt falling edge flag.
  *            @arg  FMC_FLAG_FEMPT: FIFO empty flag.
  * @retval The state of FLAG (SET or RESET).
  */
#define __FMC_PCCARD_GET_FLAG(__INSTANCE__, __FLAG__)  (((__INSTANCE__)->SR4 &(__FLAG__)) == (__FLAG__))

/**
  * @brief  Clear flag status of the PCCARD device.
  * @param  __INSTANCE__ FMC_PCCARD instance
  * @param  __FLAG__ FMC_PCCARD flag
  *         This parameter can be any combination of the following values:
  *            @arg  FMC_FLAG_RISING_EDGE: Interrupt rising edge flag.
  *            @arg  FMC_FLAG_LEVEL: Interrupt level edge flag.
  *            @arg  FMC_FLAG_FALLING_EDGE: Interrupt falling edge flag.
  *            @arg  FMC_FLAG_FEMPT: FIFO empty flag.
  * @retval None
  */
#define __FMC_PCCARD_CLEAR_FLAG(__INSTANCE__, __FLAG__)  ((__INSTANCE__)->SR4 &= ~(__FLAG__))

/**
  * @}
  */
#endif

/**
  * @}
  */

/**
  * @}
  */

/* Private functions ---------------------------------------------------------*/
/** @defgroup FMC_LL_Private_Functions FMC LL Private Functions
  *  @{
  */

#if defined(FMC_BANK1)
/** @defgroup FMC_LL_NORSRAM  NOR SRAM
  *  @{
  */
/** @defgroup FMC_LL_NORSRAM_Private_Functions_Group1 NOR SRAM Initialization/de-initialization functions
  *  @{
  */
HAL_StatusTypeDef  FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device,
                                    FMC_NORSRAM_InitTypeDef *Init);
HAL_StatusTypeDef  FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device,
                                           FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank);
HAL_StatusTypeDef  FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device,
                                                    FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank,
                                                    uint32_t ExtendedMode);
HAL_StatusTypeDef  FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device,
                                      FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank);
/**
  * @}
  */

/** @defgroup FMC_LL_NORSRAM_Private_Functions_Group2 NOR SRAM Control functions
  *  @{
  */
HAL_StatusTypeDef  FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank);
HAL_StatusTypeDef  FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank);
/**
  * @}
  */
/**
  * @}
  */
#endif /* FMC_BANK1 */

#if defined(FMC_BANK3)
/** @defgroup FMC_LL_NAND NAND
  *  @{
  */
/** @defgroup FMC_LL_NAND_Private_Functions_Group1 NAND Initialization/de-initialization functions
  *  @{
  */
HAL_StatusTypeDef  FMC_NAND_Init(FMC_NAND_TypeDef *Device, FMC_NAND_InitTypeDef *Init);
HAL_StatusTypeDef  FMC_NAND_CommonSpace_Timing_Init(FMC_NAND_TypeDef *Device,
                                                    FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank);
HAL_StatusTypeDef  FMC_NAND_AttributeSpace_Timing_Init(FMC_NAND_TypeDef *Device,
                                                       FMC_NAND_PCC_TimingTypeDef *Timing, uint32_t Bank);
HAL_StatusTypeDef  FMC_NAND_DeInit(FMC_NAND_TypeDef *Device, uint32_t Bank);
/**
  * @}
  */

/** @defgroup FMC_LL_NAND_Private_Functions_Group2 NAND Control functions
  *  @{
  */
HAL_StatusTypeDef  FMC_NAND_ECC_Enable(FMC_NAND_TypeDef *Device, uint32_t Bank);
HAL_StatusTypeDef  FMC_NAND_ECC_Disable(FMC_NAND_TypeDef *Device, uint32_t Bank);
HAL_StatusTypeDef  FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, uint32_t Bank,
                                   uint32_t Timeout);
/**
  * @}
  */
/**
  * @}
  */
#endif /* FMC_BANK3 */

#if defined(FMC_BANK4)
/** @defgroup FMC_LL_PCCARD PCCARD
  *  @{
  */
/** @defgroup FMC_LL_PCCARD_Private_Functions_Group1 PCCARD Initialization/de-initialization functions
  *  @{
  */
HAL_StatusTypeDef  FMC_PCCARD_Init(FMC_PCCARD_TypeDef *Device, FMC_PCCARD_InitTypeDef *Init);
HAL_StatusTypeDef  FMC_PCCARD_CommonSpace_Timing_Init(FMC_PCCARD_TypeDef *Device,
                                                               FMC_NAND_PCC_TimingTypeDef *Timing);
HAL_StatusTypeDef  FMC_PCCARD_AttributeSpace_Timing_Init(FMC_PCCARD_TypeDef *Device,
                                                                  FMC_NAND_PCC_TimingTypeDef *Timing);
HAL_StatusTypeDef  FMC_PCCARD_IOSpace_Timing_Init(FMC_PCCARD_TypeDef *Device,
                                                           FMC_NAND_PCC_TimingTypeDef *Timing);
HAL_StatusTypeDef  FMC_PCCARD_DeInit(FMC_PCCARD_TypeDef *Device);
/**
  * @}
  */
/**
  * @}
  */
#endif /* FMC_BANK4 */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* STM32F3xx_LL_FMC_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/